Prema Racing's Antonio Giovinazzi was at one point last in the GP2 sprint race at the Baku City Circuit but avoided the chaos to claim victory.
The Italian driver did the double, having won the feature race on Saturday, and made a last-lap move on team-mate Pierre Gasly to move into the lead.
Gasly ran deep into Turn 1, opening the door for Giovinazzi to snatch the lead on the final tour in Azerbaijan. The two were separated by just 1.7 seconds at the flag.
Behind the Prema 1-2 finish, Sergey Sirotkin was third for ART Grand Prix, with Jordan King and Arten Markelov next up.
Sergio Canamasas, Nabil Jeffri, Arthur Pic, Alex Lynn and Marvin Kirchhofer benefitted from the last safety car mayhem to complete the top 10.
The opening eight laps were fairly tame by GP2 standards but contact between Jimmy Eriksson and King at the first corner saw the safety car deployed.
Giovinazzi and Gasly moved into the mix at the next restart, where leader Nobuharu Matsushita braked after the safety car line, as other drivers behind were accelerating.
Several drivers made contact, with Gustav Malja losing his front wing and then taking out Oliver Rowland and Sean Gelael at Turn 1. Mitch Evans and Canamasas also picked up damage.
The safety car was redeployed again and on the restart, a late move and lock-up saw Raffaele Marciello and Matsushita collide, with the former continuing on to finish 11th and the latter retiring.
The restarts will now be investigated by the FIA stewards. The chaotic final stage of the race enabled Giovinazzi and Gasly to move up the order to claim a double podium.