Leclerc converted his pole position into a lead at the first corner and appeared to take control of the race during the first stint, pulling out a six-second lead before Piastri made his pit stop on lap 15.
Leclerc followed him in a lap later and in theory should have easily had sufficient cushion to hold the lead to the end.
Leclerc said he felt he and Ferrari had not made the right set-up choices for the hard tyre because he had done no race-simulation running as a result of problems in Friday practice, and he struggled after his pit stop as a result.
Piastri closed in on the Ferrari, taking his chance on fresh tyres and, on lap 20, made a brave, late dive for the inside of Turn One to take the lead.
“They had a lower downforce package and we had a bit more downforce but in the straights they were flying and that is probably where we lost the race,” Leclerc said.
“When he overtook me, I was not too worried. I thought I would stick with him and overtake him again once the tyres were up to temperature. But that opportunity never arose again. They were too quick on the straights. It was a small misjudgement but it hurts.”
It was a superb move and seemed to catch Leclerc somewhat off guard. He told Piastri in the green room before the podium that he had braked at his normal spot and expected the McLaren to sail on past the apex.
Although Piastri was now in the lead, Leclerc was not done there, and he stuck hard to the McLaren, with Perez close behind, trying to find an opening.
For many laps the three circulated together, with Ferrari urging Leclerc on over the radio.
A few times Leclerc was close enough to try a move into Turn One, but Piastri always covered the inside line and had just enough to hold the Ferrari at bay with aggressive but clean defence.
Into the closing laps, Leclerc began to struggle with his rear tyres and he dropped back from Piastri, the race now won for the Australian.
Leclerc now had to fend off Perez and Sainz, who had a lonely race for much of the duration but closed on the top three during the final stages as Piastri measured his pace to hold off Leclerc.
The dramatic climax was triggered when Perez went for a move on Leclerc at the start of lap 50, with two to go.
Leclerc held him off into Turn One and Sainz was able sneak by the Red Bull before Turn Two.
Perez got a better run through the corner and began to edge alongside the Ferrari on the following straight.
The Red Bull had its front wheel inside Sainz’s rear and the two touched, spinning violently into the wall and taking both out of the race.
The incident promoted George Russell’s Mercedes into third place – the Briton had a quiet first stint but began to make ground in the second stint and was able to pass Verstappen and Norris into what was fifth place before the Sainz-Perez crash.