Ricciardo topped an F1 podium for the sixth time ahead of Valtteri Bottas for Mercedes and Ferrari's Kimi Raikkonen, with a furious championship leader Sebastian Vettel back in eighth place.
"I don't seem to win boring races. That was unexpected," admitted Ricciardo.
The Australian came within minutes of starting from the back of the grid after an engine failure in a practice session and only a herculean effort by this Red Bull team got his car ready for qualifying where he finished sixth fastest.
It was his team who also took full advantage of a safety car on lap 33 of 56 in Shanghai after Toro Rosso teammates Brandon Hartley and Pierre Gasly tangled, leaving debris on the track.
They pitted both him and Max Verstappen for fresher tires and when the race restarted it was a question of which of them could challenge the front running Ferrari and Mercedes teams.
Verstappen from fourth looked the better bet, but the young Dutchman ran off the track in trying to overtake Lewis Hamilton for third and then collided with Vettel, getting a 10-second penalty that cost him any chance of a podium.
"I guess he misjudged it and compromised both our results," Vettel said of the attempted overtake.
"You have to have these things in mind," added the German, who is bidding for a fifth world title and won the opening two races of the season.
By contrast, Ricciardo kept his composure, putting in superb overtaking moves on Hamilton and then Bottas to take a lead he never relinquished.
Reigning champion Hamilton in fourth at least closed the gap on Vettel to just nine points at the top of the standings, but he was unhappy with his performance in qualifying and during the race.
"Yesterday and today have been a disaster for us," he told Sky Sports.
"We were just not good enough," team boss Toto Wolff admitted, but Mercedes does lead Ferrari by a single point in the constructors' championship.
Vettel early leader
Ferrari ace Vettel led from pole position and looked set for a comfortable victory until Mercedes pulled in second-placed Bottas for an earlier change of tires which left the Finn in the lead.
Red Bull had been the first team to make an undercutting move in an attempt to elevate Verstappen from third and Ricciardo from sixth, executing a difficult double pit stop to perfection.
When the Toro Rosso's collided they were the quickest to react again, with another double change to give their drivers the chance of victory, which Ricciardo grasped with both hands.
All his previous wins in F1 have come from outside the top three in qualifying, underlining his reputation as the most accomplished passer in the sport.
"Once I knew we had the pace I was not going to let it slip," Ricciardo told the post-race press conference.
With Vettel's car damaged, it left the opportunity for two-time champion Fernando Alonso to overtake him for seventh in his McLaren, while one place ahead in sixth was Germany's Nico Hulkenberg for Renault.
The F1 circuit now moves on to Baku in Azerbaijan for the fourth round, a race won by Ricciardo last year from 10th on the grid and notable for a war of words between Hamilton and Vettel after a collision.