Hamilton was leading with 15 laps to go when his engine exploded at the Sepang International Circuit.
"No, no," cried the Englishman as flames appeared at the back of his car, leaving Ricciardo to take the lead ahead of teammate Max Verstappen.
Championship leader Nico Rosberg survived a first-bend spin involving Sebastian Vettel and a 10-second penalty to take third place and extend the gap over Mercedes teammate Hamilton to 23 points with just five races remaining.
He had looked all set to snatch back the lead from Rosberg, who was relegated from second on the grid to 21st after he was hit by Vettel on the first bend.
Vettel was forced to retire with a broken front suspension in the incident that also involved Verstappen.
Hamilton had got away cleanly from pole position and sped off into the distance, clear of the trouble behind him.
An ecstatic Ricciardo celebrated his first win of the season on the podium with a "shoey" -- drinking champagne from his driving boot.
"It was a race of challenges," said Ricciardo.
"Lewis got the lead and had his problems. It went the other way in Monaco, and I will take this today," said the Australian, referring to his botched final pit stop which handed Hamilton victory in Monaco earlier in the season.
- Emotional Ricciardo -
=======================
"It has been two years since (my) last win, and it has been a bit emotional. I said two weeks ago we would win one and we did."
The Red Bull pair battled thrillingly wheel-to-wheel through six bends at one point, with Ricciardo just managing to hold off the teenage Flying Dutchman.
"We were pushing the whole race," said Verstappen.
The defensive move proved crucial as it gave Ricciardo track position at the final pit stop under the virtual safety car caused by Hamilton's demise.
Ricciardo was then able to hold onto the lead comfortably till the end.
Meanwhile Rosberg sliced his way back through the field imperiously after the first corner drama and was surprised to make the podium.
"I wished for a better day but that is the way it goes sometimes."
Hamilton now has to pick himself up quickly ahead of next Sunday's Japanese Grand Prix.
Mercedes non-executive chairman Niki Lauda said the team had "let down" Hamilton.
"I am really upset. We should not let him down with an engine failure. It was a fairly new engine, it was not old in the car," Lauda told Sky Sports television. "What went wrong I do not know and we will work to correct it.
Hamilton's failure to finish and Rosberg's third place mean that Mercedes missed a chance to clinch the constructors' championship in Sepang.
They have 553 points but Red Bull, who picked up 43 points for the one-two, have closed the gap to 194 points with a maximum of 215 up for grabs in the remaining five races of the season.
Disclaimer: No Business Standard Journalist was involved in creation of this content
