Max Verstappen secured a second win of the season after a dramatic and controversial ending to the Australian Grand Prix.
The Red Bull driver had lost out to Mercedes duo George Russell and Lewis Hamilton at the start of the race but recovered to eventually hold a comfortable lead.
But a late red flag for debris, contentiously thrown with three laps to go, left Verstappen fighting to hold on off the line.
Carnage at the restart saw another red flag, with cars crashing out and confusion reigning.
After a lengthy discussion at the FIA, a restart order for the final lap was determined, with Lewis Hamilton second and Fernando Alonso third.
But the way the race ended would have left a sour taste in the mouth for many, with numerous cars displaced from where they should have been if the race was ended under safety car conditions.
Russell made the perfect getaway to force the issue on Verstappen into turn one and with the Dutchman on a compromised line, Hamilton saw his chance.
The Briton lunged to the inside of turn three to steal second from his rival - Verstappen complaining of being forced wide.
Behind the top three, Ferrari's early-season fortunes worsened as contact with Lance Stroll took Charles Leclerc out of the race, though there was nothing the Canadian could have done to avoid the incident with the SF-23 and Aston Martin team-mate Alonso pinching him into the braking zone.
The safety car that ensued saw Perez, who started from the pit lane, pit twice to fulfil the obligation to run two tyre compounds.
Green flags flew on lap four with Russell leading Hamilton and Verstappen, with Carlos Sainz ahead of Alonso and the fast-starting Alex Albon.
But three laps later, the Williams driver span at high-speed at turn six, hitting the wall and littering the track with debris and gravel.
Another safety car allowed Russell and Sainz to pit, with the former race leader rejoining seventh.
What Mercedes couldn't have predicted was the red flag that was triggered for the track to be cleared, gifting Hamilton the lead.
Team principal Toto Wolff radioed Russell to apologise, with the response: "Not your fault guys, it was a good call."
Hamilton held firm at the restart with Verstappen under pressure from Alonso for second, but after staving off the Spaniard's attack, the Red Bull driver set off after the lead.
Predictably, the RB19 waltzed past the Mercedes in a straight line with DRS assistance with Verstappen already two seconds ahead five corners later.
Mercedes' fortunes then soured at the end of the same lap as Russell's race ended in flames with a mechanical issue in the W14, pulling across to the side of the track at pit exit to trigger a virtual safety car.
When racing resumed, Perez was a man on a mission. Stunning moves on Esteban Ocon, Oscar Piastri, and Yuki Tsunoda saw the Mexican move into ninth within three laps.
A six-second margin was then closed down within 15 laps, with Lando Norris the next victim.
The McLaren was quickly disposed of, as well as Nico Hulkenberg's Haas with a move into turn 11.
Sainz was also racy - a stellar dummy lunge into turn three gave the Ferrari driver fourth ahead of Pierre Gasly's Alpine.
Red flag drama
Verstappen's easy run to victory was threatened by front-locking with 11 laps to go, with a trip to the grass costing him four seconds.
Then contact with the barrier at the exit of turn two for Kevin Magnussen left a tyre just off the racing line on entry to turn three, triggering a safety car with five laps remaining.
A red flag was then thrown again on lap 55, leaving a two-lap sprint to the end.
The decision to stop the race at such a late stage drew ire from Verstappen, who angrily questioned on team radio: "What the f**k do you mean red flag?"
Verstappen held the lead at the start but carnage ensued with an immediate red flag.
Sainz and Alonso collided to take the Aston Martin out of the podium at turn one.
Gasly locked up at the same time and ran wide, forcing Perez off with him. When the Alpine rejoined, he made contact with team-mate Ocon, both drivers crashing heavily into the exit barriers at turn two.
At the back of the field, Logan Sargeant and Nyck de Vries got together on entry to turn one.
With the cars returning to the pits at the beginning of the final lap under red flag conditions, the race was effectively ended early but confusion around the finishing order was created.
Racing did not reach the end of the first sector, which is usually used to determine the first official order ranking after a start.
With one lap to run, a decision was made to shuffle the restart order back to one resembling the grid before the carnage, minus those too damaged to participate.
Whilst the drivers awaited the ceremonial resumption, Sainz was handed a five-second penalty for his collision with Alonso, leaving the Ferrari driver perplexed in his cockpit.
When the cars crossed the line to end the race, Verstappen led home Hamilton and Alonso, who was given a reprieve.
Stroll was promoted to fourth by Sainz's penalty ahead of Perez and Norris, who secured McLaren's best finish of the season.
Hulkenberg finished seventh, but will rue the FIA's decision having made his way through the carnage to fourth at the restart - which would have been a first F1 podium with Sainz's penalty. The Haas ground to a halt after the finish line.
Piastri clinched his first F1 points in front of his home crowd in eighth, with Zhou Guanyu and Tsunoda rounding out the top 10.
Valtteri Bottas was 11th and Sainz dropped to 12th, the last of the finishers.