After a start in cool, windy conditions that made it hard to get enough grip, the safety auto was out nearly immediately on lap 1 as several cars collided in the middle of the pack.
Bottas looked poised to take Mercedes' first win of 2018 after perfectly executing a Safety Car restart with five laps left.
The victory comes after team mate Valtteri Bottas suffered a puncture tire with three laps left while in lead and ended a six race drought for the four times champions.
That freed Hamilton into the lead with Raikkonen a comfortable second as Perez drafted Vettel, struggling with a flatspotted tyre, to score a shock podium despite Vettel's efforts to retaliate. Stoffel Vandoorne of McLaren was the fastest to be eliminated in Q1, while Pierre Gasly will start in 17th place after the driver almost avoided contact with Brendon Hartley of Torro Rosso, who was dealing with a puncture in Q1.
Hamilton was now the race leader and clinched one of the most unlikely wins of his career.
"So it's a bittersweet feeling: fantastic to get the win on the board and to be leading the drivers' championship, but also disappointed because the quickest guy DNF'd with a puncture - and because we know there is still work ahead of us to improve the pace of the vehicle in what will be a close three-way fight for the rest of the season". However, no further action was taken.
Sainz climbed back into fifth thanks to the turmoil ahead of him, claiming Renault's best finish since Vitaly Petrov was fifth in Canada in 2011. He qualified sixth, one place behind the second Red Bull of Max Verstappen. It seemed fair. But Ricciardo locked up and ploughed into the back of the Dutchman.
It forced the Finn out of the race and handed the lead to Hamilton with just three laps remaining.
On lap 11, Nico Hulkenberg lost control of his Renault and clipped a wall at Turn Four as Ricciardo began a series of attacks on his Red Bull team-mate, the pair banging wheels to the consternation of their pit wall. Max Verstappen (Red Bull) - 189. Kimi Raikkonen (Ferrari) - 484.
Before the very bad denouement, there was some marvellous wheel-to-wheel racing between Max Verstappen and Daniel Ricciardo, with the Australian making a pass at the first corner to take his team-mate's fourth position on Lap 34. By the end of the ninth lap, Sainz had passed Verstappen, and Hulkenberg had not only passed Ricciardo, he was now closing in on Verstappen. This time Verstappen had no answer, but in their pit stops a few laps later, Verstappen emerged ahead of his teammate despite pitting one lap later.
Verstappen's vehicle was lifted briefly into the air and both battered Red Bulls skated down the escape road into retirement.
Wolff said: "That was just a brutal race and probably exactly the kind of Grand Prix that fans want to see, with twists and turns at every point".