Morocco ace Mouhssine Iajour put Raja in front six minutes after the interval before former Barcelona star Ronaldinho restored parity for the Brazilians with a sublime free kick on 64 minutes.
The hosts, however, regained their lead through a Mohsine Moutouali spot-kick six minutes from time as Central African Republic midfielder Vianney Mabide ensured the win with a third goal deep into stoppage time.
Raja now become the first Arab side to make it to the World Cup final as they meet Bayern Munich, who beat Asian champions Guangzhou Evergrande 3-0 a day earlier, on December 21.
Mineiro will vie for the competition's bronze medal with Guangzhou on the same day.
Mexico's Monterrey have secured fifth place after crushing African champions Ahli 5-1.