Changing weather conditions and several safety car outings played havoc with team tactics, allowing Hamilton to seize a podium finish just 24 hours after trudging despondently away from his smouldering Mercedes after an engine fire in qualifying.
Hamilton's team-mate and title rival Nico Rosberg came fourth, having failed to overtake the Briton in a desperate last lap battle. Although Hamilton only trimmed his team-mate's points lead by three to 11, it was an important psychological blow in a race where the polesitter Rosberg had been expected to extend his advantage significantly.
Those inter-team tensions surfaced repeatedly during the last third of the race, as Rosberg, loitering in the slipstream of his team-mate, demanded to be allowed to go past. Hamilton, protecting his fourth place, responded that he would let him past when he was in a position to overtake, but while there was still a second's difference between the pair, he refused to slow down.
Grosjean to test Hamilton's 2019 Mercedes at French GP circuit
Rosberg's advantage from pole was reduced significantly due to several accidents on the track resulting in safety cars and yellow flags being employed, meaning the chasing pack took the opportunity to pit relatively early without losing too much ground.
Fernando Alonso finished second for Ferrari, having led until the final few laps when Ricciardo, on significantly fresher tyres, stormed past Hamilton and Alonso.
Felipe Massa took fourth in his Williams, with Kimi Raikkonen finishing sixth for Ferrari. Sebastian Vettel managed seventh for Red Bull, and Valtteri Bottas was eighth.
Jean-Eric Vergne, the subject of another of Rosberg's complaints for driving too fast past accident debris, ended in ninth; with Jenson Button taking tenth for McLaren.
HUNGARIAN GP RESULT
1-Daniel Ricciardo (Red Bull)
2-Fernando Alonso (Ferrari)
3-Lewis Hamilton (Mercedes)
4-Nico Rosberg (Mercedes)
5-Felipe Massa (Williams)
6-Kimi Raikkonen (Ferrari)
7-Sebastian Vettel (Red Bull)
8-Valtteri Bottas (Williams)
9-Jean-Eric Vergne (Toro Rosso)
10-Jenson Button (McLaren)
Portuguese Grand Prix
Race review: Hamilton and Mercedes flex mental muscles, Alonso shows promise
Portuguese Grand Prix
Verstappen completes unwanted 'track limits' triple