Youssef En-Nesyri scored with a first-half header as Morocco became the first African team to reach the World Cup semifinals with a thrilling 1-0 win over Portugal here on Saturday.
Morocco took the lead on the stroke of halftime when En-Nesyri met Yahia Attiat Allah's cross with a towering header at the far post.
Portugal dominated possession and had several chances to equalize in the second half, including a gilt-edged opportunity for Cristiano Ronaldo in stoppage time.
The result means Morocco will meet either England or France at Al-Bayt stadium in Al-Khor on December 14 for a place in the final four days later.
The fixture was almost certainly Ronaldo's final appearance at football's showpiece tournament. The former Manchester United, Real Madrid and Juventus star looked a forlorn figure as he walked off the pitch with his head bowed immediately after the final whistle at Al-Thumama stadium.
Ronaldo, who has been capped 195 times and scored a record 118 goals for his country, will be 41 when the next World Cup begins in the United States, Canada and Mexico.
Portugal manager Fernando Santos again opted to start with Goncalo Ramos at the head of his attack after the Benfica striker's hat-trick in a 6-1 victory over Switzerland in the round of 16.
That meant there was no place for five-time Ballon d'Or winner Ronaldo, who began on the bench for the second consecutive game.
Santos made just one change to his lineup, with Wolverhampton Wanderers captain Ruben Neves taking the place of Real Betis midfielder William Carvalho.
Morocco boss Walid Regragui, meanwhile, was forced to leave out defenders Nayef Aguerd and Noussair Mazraoui due to injury. They were replaced by Yahia Attiyat Allah and Jawad El Yamiq.
Portugal began brightly with Joao Felix and Raphael Guerreiro denied in the early minutes by Morocco's miserly defense.
Felix made clean contact with a diving header after Bruno Fernandes' floating free-kick only to see his shot was parried away by goalkeeper Yassine Bounou. Guerreiro then had a first-time volley blocked by Achraf Hakimi after another Fernandes delivery into the penalty area.
But Morocco soon composed themselves as En-Nesyri headed over from a corner and Hakim Ziyech cut inside Otavio before lashing a left-footed drive wide.
Morocco suddenly had Portugal on the back foot. En-Nesyri should have done better when he leapt above his marker following a Ziyech free-kick before directing his header over the bar.
Selim Amallah blazed over after Attiyat Allah's cross from left and then Sofiane Boufal fired an attempt straight at Portugal goalkeeper Diogo Costa on the counterattack.
After a slow start, Felix began to assert his influence, shooting narrowly wide with the outside of his right boot after El Yamiq's headed clearance and then sending a first-time effort over the top after a cross from the left.
Morocco took the lead in the 44th minute following Attiyat Allah's probing run and cross from the left wing. En-Nesyri rose highest to beat Jota in an aerial duel before thumping his header into an unguarded net.
Fernandes almost struck a spectacular equalizer as he tried his luck from an acute angle only to see the ball deflect off the crossbar.
Attiyat Allah then blazed wide with only Jota to beat after being played through on goal by Azzedine Ounahi.
Morocco picked up where they left off after the interval as they ran at Portugal's defense without fear. El Yamiq forced a reflex save from Costa after connecting with Ziyech's cross and Ounahi drilled a shot over the crossbar.
Ronaldo was introduced in the 51st minute as a replacement for Neves and the veteran forward received a mixed chorus of jeers and cheers from the mostly pro-Morocco crowd.
The change appeared to make a difference as Portugal began to run with the ball while Morocco retreated deeper into their own half.
Ramos had has first genuine chance of the night just before the hour, heading wide from 12 yards after Otavio's cross and Fernandes then hammered a shot over the bar following Felix's jinking run and pass.
The latter drew a brilliant one handed save from from Bounou after running onto Ronaldo's one-touch pass and curling a dipping shot that appeared headed for the far corner.
Ronaldo then timed his run to perfection by latching onto a through ball before lashing a low attempt straight at Bounou.
Morocco were handed a numerical disadvantage after Cheddira, a 65th-minute replacement for Amallah, was shown his second yellow for a crude challenge on Felix.
It was pulsating end-to-end football as Morocco squandered a golden chance to extend their lead through Yahya Jabrane, who shot straight at Costa when he was through on goal.
Portugal were also guilty of missing late chances and Pepe will be ruing a free header at the far post after Rafael Leao's cross.