McLaren's Lando Norris rounded out the podium but he was gifted third place when Ferrari's Charles Leclerc flew off the track late in the race.
Leclerc had changed tyes in an effort to chase down Perez and set the fastest lap but he misjudged a tricky chicane and bounced up off a sausage kerb and off the track.
The championship leader was in third at the time and had his sights set on second place, but he did well not to crash out of the race completely and recover to finish in sixth.
It was a day to forget for Ferrari at their home race, with Carlos Sainz ruled out of the race when he collided with Daniel Ricciardo on the very first corner on the opening lap.
Sainz was fuming and believed Ricciardo was at fault for the incident, but he wasn't penalised.
It's the second race in a row Sainz has failed to finish after he spun off the track at the Australian Grand Prix.
"Ferrari are the ones that are going to feel like they've been punched in the stomach after today," Sky Sports commentator Paul Di Resta said.
"What could they have done to get some luck? With all that momentum, all that red in the grandstand, it's just not happened."