A stoppage-time winner from Abdelilah Hafidi earned Raja Casablanca a 2-1 victory over Auckland City that sent the Moroccans through to the quarter-finals of the Club World Cup.
Mouhssine Iajour slotted past the New Zealand side's goalkeeper Tamati Williams in the 39th minute to register the first goal of this year's tournament, which began at the Stade Adrar in Agadir.
However, Fijian striker Roy Krishna equalised in the 63rd minute to set up a tense finale.
Extra-time beckoned until Hafidi popped up to tuck home a rebounding header at the death, booking Casablanca a meeting with Monterrey of Mexico in three days' time.
The first quarter-final sees Chinese outfit Guangzhou Evergrande tackle Egyptians Al-Ahly.
The winners of that match will face German and European champions Bayern Munich with Atletico Mineiro also taking part in Morocco.