Hamilton's Mercedes teammate Valtteri Bottas snatched second place from 18-year-old Williams driver Lance Stroll in the final straight.
Hamilton's Mercedes teammate Valtteri Bottas snatched second place from 18-year-old Williams driver Lance Stroll in the final straight, as Vettel finished fourth ahead of Hamilton to extend his championship lead to 14 points.
Despite Ricciardo's win, the race will be remembered for the angry confrontation between former world champions Vettel and Hamilton.
Ferrari star Vettel was handed a 10-second stop-go penalty for "dangerous driving" after he deliberately drove into Hamilton's Mercedes while both were following the safety car.
Vettel claimed Hamilton had braked in front of him and he responded by driving into the back of his rival before then bumping the Briton from the side.
"I think it's just not driver conduct. It's dangerous driving and to get a 10-second penalty for that... I don't need to say anything else," Hamilton told Sky Sports.
Vettel pleaded innocent.
"Nothing happened, did it? He brake checked me as well, so what do you expect?," the German told Sky.
"I'm sure he didn't do it on purpose but for sure it was not the right move. If I'm struggling, people at the back struggling even more, so I don't think it was necessary.
"I got damage, he risked damage. He's done something similar in China at the restart a couple of years ago so it's not the way to do it, I think.
"I passed him because he pitted. After the incident, we were side by side, I raised my hand and told him, well I didn't say anything, but showed him that I wasn't happy with that."
Making the most of a series of extraordinary incidents and interventions in an action-packed race, which included three safety car interventions and a red-flagged stoppage, Ricciardo, who started 10th, roared home 3.904 seconds ahead of the rest to deliver his first win of the season.
Esteban Ocon of Force India was sixth ahead of Kevin Magnussen of Haas, Carlos Sainz of Toro Rosso, who also survived a first-lap collision, two-time champion Fernando Alonso, who scored McLaren's first points of the year in ninth, and Pascal Wehrlein of Sauber.
Hamilton, who had dominated after a strong start from his 66th pole position, was also undone by a loose headrest that caused him to be ordered to pit for repairs, for safety reasons.
Bottas meanwhile produced a brilliant drive to take his fifth podium finish of the season, having dropped to the back of the field after a first-lap bump with fellow Finn Kimi Raikkonen.
Further chaos unfolded when Daniil Kvyat stopped, his Toro Rosso having lost all electrical power on lap eight. A safety car was deployed on lap 12, for the first time.
By then, after a great scrap with Sergio Perez, Max Verstappen was also forced to retire with an engine failure, his fourth retirement in six outings in his Red Bull.
The first safety car came in after 16 laps, racing resuming with Perez making an attack on Vettel who resisted, before another safety car, the second, was deployed due to debris.
Racing resumed, for a third time, on lap 19, but only after the incident in which Vettel hit the rear of Hamilton’s car, under braking as the leader tried to avoid the slow-moving safety car.
It appeared Hamilton had done nothing untoward, but the German was clearly irate and pulled alongside the Mercedes, waving an arm, before turning into his car.
It seemed a clear case of Vettel losing his temper and causing an accident, but both emerged unhurt as the serious action resumed and Raikkonen picked up debris and a puncture to trigger a third safety Car intervention -– after only 20 laps.
The racing resumed, for a fifth time, behind a safety car and when it came in after one lap Hamilton pulled away and Ricciardo dived past Stroll to snatch third.
Nico Hulkenberg of Renault then followed team-mate Jolyon Palmer into retirement after the German crashed into the wall while Felipe Massa slowed and retired with a broken damper on his Williams.
Hamilton opened up a 2.7 seconds lead before he was told by Mercedes that his headrest was loose. Behind him, team-mate Bottas was back up to eighth and Vettel was closing.
Hamilton was then ordered to pit, on safety grounds, and rejoined ninth with his headrest secured.
By lap 40 of the 51, Ricciardo had the lead which he would not surrender.