In a predominantly empty Accra Sports Stadium, Morocco went two goals up inside five minutes.
With just less than a minute on the clock, Maroune Chamakh found himself one-on-one with Namibian goalkeeper Abisai Shiningayamwe, and when his initial shot was deflected onto the post he turned and laid the ball across for Alloudi to tuck the ball home.
Moments later Alloudi had a second, exchanging passes with Youssef Hadji before bursting past a defender and expertly finishing past Shiningayamwe with the outside of his right foot.
Morocco appeared to be in total command of the game, but from nowhere Namibia pulled a goal back.
Brian Brendell cut inside from the right wing to collect a pass from midfield and steadied himself to fire a superb left-footed shot into the bottom right corner.
Morocco responded by attacking, and any hopes of a comeback were quashed just before the half-hour mark when Alloudi claimed his hat-trick.
Porto midfielder Tarik Sektioui twisted his marker inside and out on the left wing before delivering a cross to the back post which Alloudi headed firmly home.
Morocco continued to press, with Youssef Safri and Sektioui stinging Shiningayamwe's fingers with well-struck shots, and five minutes before half-time they increased their lead.
Mickael Chretien's surge infield from the right was halted by a crude challenge from Jamu Ngatjizeko, and referee Evehe Devine pointed to the spot.
The impressive Sektioui stepped up and swept a confident penalty into the bottom-left corner to give his side a three-goal half-time lead that they fully deserved.
With the game beyond them, indiscipline began to creep into Namibia's play, and ten minutes into the second-half Collin Benjamin was shown the yellow card for a stamp on Abderrahmane Kabous.
Minutes later Richard Gariseb was lucky to get away with a caution after a high, studs-up tackle on Alloudi that forced the hat-trick hero to be replaced by Youssef Mokhtari.
The bookings and a full complement of substitutions took the pace out of the game, until Moroccan substitute Moncef Zerka headed home from a corner with fifteen minutes remaining.
The result takes Morocco top of Group A after hosts Ghana's 2-1 victory over Guinea.
Morocco - 5 (Soufiane Alloudi 2' (shot), Soufiane Alloudi 5' (assist - Youssef Hadji), Soufiane Alloudi 28' (assist - Youssef Hadji), Tarik Sektioui 40' (pen), Moncef Zerka 73' (assist - Youssef Safri corner)
Namibia - 1 (Brian Brendell 23' (shot)
Yellow cards: Badr El Kaddouri 45, Quinton Jacobs 38, Collin Benjamin 56, Richard Gariseb 60, Jamunavandu Ngatjizeko 62, Lazarus Kaimbi 71
MOrocco: 12 Khalid Fouhami (G), 2 Michael Basser, 21 Badr El Kaddouri, 6 Elamine Erbate, 4 Abdeslam Ouaddou, 20 Youssouf Hadji (Moncef Zerka 70), 18 Abderrahman Kabous, 15 Youssef Safri, 7 Soufiane Alloudi (Youssef Mokhtari 63), 17 Marouane Chamakh, 10 Tarik Sektioui (Hicham Aboucherouane 67).
Namibia: 16 Abisai Shiningayamwe (G), 6 Franklin April (Letu Shatimiene 46), 5 Richard Gariseb, 13 Michael Piennar, 7 Collin Benjamin, 14 Brian Brendell, 17 Quinton Jacobs (Meraai Swartbooi 77), 22 Jamunovandu Ngatjizeko, 8 Oliver Risser, 15 Rudolph Bester (Pineas Jacob 64), 19 Lazarus Kaimbi.