The Mahindra Racing driver look destined to finish second after pole sitter Sebastien Buemi led for most of the race.
But with just four laps to go Rosenqvist stunned the more experienced Swiss driver diving down the inside at Turn 7 to pass Buemi before going on to take the checkered flag.
It was the 26-year-old's second win in as many races following his triumph in Hong Kong last month -- the Swede inherited first place after Daniel Abt was disqualified
for an infringement of FIA rules in the second race of the weekend at the Central Harborfront Circuit.
Victory in Marrakech sees Rosenqvist overtake Britain's Sam Bird at the top of the drivers' standings after three rounds with 54 points to Bird's 50.
Bird had qualified second behind Buemi but gearbox problems during the first half of the race meant the DS Virgin Racing driver had to settle for third.
"What a day ... I was saving my energy behind Sam and Seb, and in the second stint I saw a gap and went for it," Rosenqvist said.
"Leading the championship after only three races is a fantastic thing."
Nelson Piquet Jr. turned in another solid performance finishing fourth for his new team, Jaguar Racing. The Brazilian also set the the fastest lap of the race. Jean-Eric Vergne finished fifth.
Jose Maria Lopez marked his return
to Formula E with a sixth place finish for the Dragon team.
Mahindra Racing completed a hugely satisfying weekend as Nick Heidfeld came home seventh picking up six points.
The result means the Indian team extends its lead to 18 points over DS Virgin Racing in the constructors' championship.
There were also points for Formula E debutant Tom Blomqvist who finished eighth with Nico Prost and Alex Lynn making up the top 10.
Rosenqvist, who impressed so much as a Formula E rookie last season, now leads the title race by four points from Bird with Techeetah's Vergne in third.
Buemi's second place finish sees him move up to sixth in the overall standings.
His arch rival and reigning champion Lucas di Grassi remains pointless after the Brazilian retired with battery trouble eight laps into Saturday's race.
Round four of the 2017/18 championship takes place in Santiago, Chile on February 3.