JEROME D AMBROSIO held off Robin Frijns by just 0.143 seconds in a nail-biting final lap at the Marrakesh E-Prix after starting in tenth place.
BMW threw away a comfortable one-two lead after Antonio Felix da Costa and Alexander Sims collided with just ten minutes remaining.
The pair both locked up and Felix Da Costa was on the inside but as Sims turned in he went into the barriers while Sims was able to keep his race alive and finish in fourth.
And as the stewards were moving Felix Da Costa s there was a safety car until the final lap.
This led to a frantic sprint to the finish line with D Ambrosio winning the race after climbing nine places.
Virgin duo Frijns and Sam Bird finished second and third respectively as they also benefited from BMW s mishap.
Bird came through unscathed after a moment of madness from Jean-Eric Vergne on the first turn of the race.
The defending champion attempted an ambitious move down the inside of pole-sitter Bird but ran out of room and span off which caused chaos and set him back to last place.
Pascal Wehrlein s highly-anticipated debut ended in disaster after he was forced to retire just five minutes into the race.
The former F1 star received damage after the carnage caused by Vergne as it led to Lucas Di Grassi coming into the back of the German.
Formula E: Marrekesh E-Prix race result
1. Jerome d Ambrosio BEL Mahindra Racing
2. Robin Frijns NED Envision Virgin Racing
3. Sam Bird GBR Envision Virgin Racing
4. Alexander Sims GBR BMW i Andretti Motorsport
5. Jean-Eric Vergne FRA DS Techeetah
6. Andre Lotterer BEL DS Techeetah
7. Lucas di Grassi BRA Audi Sport ABT Schaeffler
8. Sebastien Buemi SUI Nissan e.dams
9. Mitch Evans NZL Panasonic Jaguar Racing
10. Daniel Abt GER Audi Sport ABT Schaeffler
11. Jose Maria Lopez ARG GEOX Dragon
12. Maximilian Gunther GER GEOX Dragon
13. Edoardo Mortara SUI Venturi Formula E Team
14. Nelson Piquet Jr. BRA Jaguar
15. Oliver Rowland GBR Nissan
16. Oliver Turvey GBR NIO
17. Tom Dillmann FRA NIO
18. Felipe Massa BRA Venturi
Ret. Antonio Felix da Costa POR BMW
Ret. Gary Paffett GBR HWA
Ret. Pascal Wehrlein GER Mahindra
Ret. Stoffel Vandoorne BEL HWA