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.
Nelson Piquet Jr. turned in another solid performance for his new team, Jaguar Racing taking fourth spot, and setting 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.
"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 into the season is a fantastic thing."
Rosenqvist, who impressed in his rookie Formula E season last year, leads the title race by four points from Bird with Techeetah's Vergne in third.
After picking up a single point from the opening two races Buemi's second place finish moves him up to sixth in the drivers' title race.
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.