Sergio Perez has closed in on the lead in the Formula 1 drivers' championship with victory at the Azerbaijan Grand Prix.
The Mexican beat his Red Bull teammate and championship leader Max Verstappen, taking advantage of an opportune safety car that promoted him to the lead.
Ferrari's Charles Leclerc came third while Australian Oscar Piastri finished 11th following a frustrating race.
But the race was marred by a frightening incident at the end of the race, in which people had to jump out of the way of a car in the pit lane.
Alpine driver Esteban Ocon came into the pits while Sergio Perez was on the final lap. Ocon had not made his mandatory pit stop and had to come in before the end of the race to avoid being disqualified.
However, people started crowding the pit lane, including photographers, marshalls and members of the victorious Red Bull pit crew, according to Sky Sports reporter Ted Kravitz.
As Ocon came into the pits, he had to quickly slow down as people took evasive action to avoid the car.
"Oh what is this about? This is a shambles, absolute shambles," Kravitz said as Ocon came into the pits.
"It's a lucky escape I think," former driver Karun Chandhok said in commentary.
"Absolute madness to allow all those people into the pit lane when there is live racing on."
F1's governing body, the FIA, was found to have breached two articles of its international sporting code, including "any unsafe act or failure to take reasonable measures, thus resulting in an unsafe situation".
The stewards met with FIA representatives and a statement said measures would be put in place to make sure a similar situation does not happen again.
"We noted that it was not unusual for the representatives to allow such persons into the pit lane just before the end of the race, in the usual course of preparation for parc ferme [gathering of teams and media] and the podium ceremony," the stewards said.
"However, in this case, there was one driver that had to pit in the last lap and this created a very dangerous situation for those that were in the pit lane at the time.
"We considered that it was fortunate that there were no serious consequences on account of what happened today."
Perez secures win after fortunate safety car
Coming off winning the sprint race on Saturday, Perez came from third to win the main race around the streets of Baku.
Verstappen, who started second behind Leclerc, took the lead on lap 3 and was looking comfortable until a safety car on lap 11.
Verstappen pulled into the pits at the end of lap 10, after complaining to his team that he was sliding through the corners.
At a similar time, AlphaTauri driver Nick De Vries went off track which brought the safety car out.
The safety car hurt Verstappen, who could do nothing as Perez and Leclerc were able to pit while everyone else was driving slowly.
When the safety car pulled into the pits at the end of lap 13, Perez led Leclerc with Verstappen now third.
Verstappen overtook Leclerc on the first lap after the restart, but Perez was near-flawless for the rest of the grand prix.
The 33-year-old maintained a steady gap to his teammate, never looking threatened as he took his second win in four races this season.
"It really worked out today for us, we managed to keep the pressure on Max as we had better degradation on that first stint," Perez said.
"I think it was very close between us, we pushed to the maximum today, we both hit the wall a few times but we managed to keep [Verstappen] under control."
Verstappen's lead over Perez in the drivers' championship is six points.