Hamilton had led the race confidently off the line while chaos unfolded behind him between teammate Nico Rosberg, Red Bull Racing’s Max Verstappen, and Ferrari’s Sebastian Vettel.
Vettel speared into the side of Rosberg while attempting to pass Verstappen on the inside of the first turn, spinning the Mercedes around and putting himself out of the race in the process.
Rosberg dropped back to 21st, allowing Hamilton to cruise at the front unchallenged.
Max Verstappen lost two places and fell to fifth, and though he was making progress through the field, the Dutchman stopped for a set of soft tyres on lap eight during a virtual safety car triggered by Romain Grosjean’s beached Haas car.
Hamilton made his stop on lap 21 and Ricciardo pitted a lap later — both for the hard compound, giving both having the option to not stop again.
Verstappen then switched to a new set of hard tyres, putting Ricciardo in a defensive position on older rubber as Max rapidly closed the gap to within one second after ten laps.
As the teammates tussled, Kimi Räikkönen was attempting to defend fourth place against Rosberg’s successful charge through the field on his soft-hard-hard strategy.
Rosberg made a bold move on the Finn on the inside of turn two, making it stick with a lunge on the brakes after following Räikkönen around the outside of turn one.
Though neither car was damaged after light contact, the stewards penalised Rosberg 10 seconds for dangerous driving.
The simmering race was brought to boil two laps later when Hamilton pulled to the side of the track with his burning engine, triggering a virtual safety car.
“I just can't believe that there are eight Mercedes [engined] cars and only my engines are the ones that have been going this year,” Hamilton told Sky Sports UK.
“Something just doesn’t feel right — it’s a brand new engine, done one race with it. It's just odd.”
Red Bull Racing, now primed for victory, had a dilemma on its hands: Verstappen was on a newer set of tyres and had already been harassing Ricciardo for his position before the caution period neutralised the battle.
Team principal Christian Horner and his pit wall, faced with a potentially ugly intra-team battle, pitted both drivers for a set of soft tyres for the final stint, levelling the playing field.
The pair ran within two second of each other to the finish, Verstappen occasionally nibbling away at his teammate’s lead, but neither driver could elicit and advantage on the same compound in identical cars.
The race was a stalemate, and Ricciardo took his first victory since 2014.
“It was a race of challenges,” the Australian said on the podium after drinking his victory champagne from one of his race boots, as is now his custom.
“It’s been a pretty emotional two years since the last win.
“Two weeks ago after the [Singapore Grand Prix] I said we’d win one this year, and here we go, we got this.”
Ricciardo recalled his lost victory in Monte Carlo, where a botched tyre stop by is team scotched his chances of defeating Lewis Hamilton on the sport’s most famous circuit.
“I’m not really on for believing in a whole lot, but obviously it went the other way in Monaco, so I’ll take this today — no hard feelings to Lewis, but I’ll definitely take the win.”
Verstappen, who was voted driver of the day by the fans, was happy to finish second in such a trying grand prix.
“I have to say after the champagne I feel good, it woke me up again!” the teenager said.
“Of course we were pushing the whole race, so definitely after the race we have to take a break.”
Nico Rosberg managed to hold third place despite his penalty, the German opening the gap to Räikkönen behind in the final stint to 13.2 seconds, negating the 10-second deduction.
“At turn one I thought it was all over, so I’m certainly happy to fight back all the way to the podium, that’s been great,” he said.
With Hamilton failing to finish, Rosberg now leads the drivers championship race by 23 points.
“I wished for a better day today, but that’s the way it is sometimes. It’s a good moment in general, now looking forward now to the next one.”
Formula One continues next weekend at Suzuka for the Japanese Grand Prix.