Cristiano Ronaldo scored his fourth goal in two World Cup matches as Portugal won 1-0 against a Morocco side that created plenty of chances but were eliminated from the tournament.
Morocco made a bright start and threatened inside the opening couple of minutes when Noureddine Amrabat crossed and Hakim Ziyech set up Khalid Boutaib, whose header cleared the bar.
But any optimism that may have been generated was shattered when, after four minutes, Ronaldo scored his fourth goal in two games when Joao Moutinho crossed and Ronaldo, all alone, thundereda header high into the net.
With nine minutes on the clock he was close to doubling his tally, spinning away from a defender before sending a low shot just wide of the far post.
Three minutes later, however, Morocco went close when, from a corner, Manuel da Costa powered in a downward header but Rui Patricio saved.
And when they came forward again soon after the quarter-hour mark, Cedric produced a good block to clear a Nabil Dirar cross.
Ziyach tried a low strike from distance, stopped by Patricio, as Morocco continued to apply pressure.
With 25 minutes played, Ronaldo went down after a Medhi Benatia challenge but was soon back on his feet, and then Amrabat got away from Raphael Guerreiro and went down inside the area but no penalty was given.
Five minutes later, Portugal won a free kick on the edge of the box, with Ronaldo — inevitably — the player to take it, but his effort hit the wall.
Ten minutes from the break, Karim El Ahmadi shot over after neat approach play, with Portugal having offered little threat since Ronaldo’s early breakthrough.
But out of the blue they almost had a 2-0 lead, Ronaldo the provider with a lofted pass for Goncalo Guedes, whose shot was well saved by Munir.
Morocco had one more chance to level before the break when a cross was flicked on but just eluded Benatia at the far post.
But c threatened in the opening moments of the second half, a short corner providing half a chance for Jose Fonte, who was unable to get his header on target.
Ronaldo blasted wildly off target before Patricio clutched a curling strike from Younes Belhanda and then made a brilliant diving save to keep out Belhanda’s header.
Portugal made a change as the hour approached, Bernardo Silva making way for Gelson Martins, before Morocco wasted a chance when Benatia thrashed over from 15 yards.
Guerreiro was booked for pulling back Amrabat as the pressure on Portugal grew and Morocco made a change, swapping Boutaib for fellow forward Ayoub El Kaabi and Portugal bringing on Bruno Fernandes for Joao Mario.
As the game entered the final 15 minutes, another Portugal change saw Mehdi Carcela come on and Belhanda go off.
With 10 minutes to go, another Morocco chance went begging as Benatia failed to make a proper connection with a header and the ball bounced wide.
Ronaldo was fouled just outside the area but sent his free kick crashing into the wall, and the referee waved play on when he then won the ball back and tumbled inside the area.
Moutinho came off and Adrien Silva was introduced for Portugal, who had to survive more scares when Ziyach’s strike was brilliantly blocked by Pepe and Benatia fired over in stoppage time.