Cristiano Ronaldo headed Portugal’s winner as Morocco became the first team to be knocked out of the World Cup.
Ronaldo’s fourth goal of the tournament, from Joao Moutinho’s cross, saw him become the leading European goalscorer in international football with 85 goals.
Morocco had several chances to equalise, Rui Patricio’s excellent one-handed save denying Younes Belhanda at the Luzhniki Stadium in Moscow.
Portugal move to the top of Group B.
They are one point above Iran, who play Spain at 19:00 BST on Wednesday.
Belhanda thought he had levelled after meeting a free-kick with his head, but Patricio, who has signed for Premier League newcomers Wolves, produced an instinctive stop.
Medhi Benatia wasted four chances, including a snatched shot in stoppage time, while Belhanda fired straight at Patricio before Morocco’s exit from the tournament was confirmed with one match still to play.
The North African nation, beaten 1-0 by Iran in their opening game, are playing at the World Cup for the first time in 20 years.