Sebastian Vettel for Aston Martin and Pierre Gasly for Alpha Tauri completed the unexpected podium.
Verstappen crashed with five laps to go and the race at his mercy. Hamilton then locked up at the restart when on target for second.
The drama on the streets of Baku left Verstappen retaining the lead in the drivers standings.
This was the first win for Perez since joining Red Bull.
Perez said: "I'm so happy for today. Normally Baku is pretty crazy but I have to say sorry to Max.
"He deserved the win today and it would have been good for the team to get a 1-2 but the win is a fantastic result.
He inherited the lead when his teammate Verstappen's left rear tyre shredded triggering a high-speed crash in the straight as he was set to cash in on his second straight win and third of the season.
"Tyre," shouted a distraught Verstappen on the team radio.
After a red-flag stoppage lasting over half an hour to clear debris from Verstappen's stricken car the grand prix resumed with a two lap sprint to the chequered flag.
Hamilton looked to have the measure of Perez but spun off at turn one leaving Perez to collect an unlikely win.
Pole-sitter Charles Leclerc came in fifth and Hamilton out of the points like Verstappen in 15th.