A clever switch of strategy put Raikkonen on the faster soft tyres for his final stint, during which he was able to haul in the medium-tyred Rosberg, before passing the German - who like Hamilton had brake issues - on the penultimate lap.
Raikkonen’s team mate Sebastian Vettel had been in contention for second until a mid-race error forced to him to make an unscheduled pit stop for a new nose and he ultimately came home fifth, just losing out to Williams’ Valtteri Bottas.
Both Red Bulls scored points, with Daniel Ricciardo sixth and Daniil Kvyat ninth, though the former’s car expired as he crossed the finish line. Between them were Lotus’s Romain Grosjean and Force India’s Sergio Perez.
It was Hamilton who made the best start to protect his lead on the first run down to Turn 1, but Rosberg initially lost out to Vettel and Raikkonen and dropped to fourth - before bold overtaking moves under braking for Turn 1 lifted him above the Finn on lap four and the German on lap nine.
At that stage it seemed that Mercedes had the upper hand, especially as both ran longer first stints than Vettel. The lead trio opted for a second set of soft Pirellis for their second stints, meaning they would finish with a set of mediums. But when Ferrari hedged their bets and put Raikkonen on mediums for his middle stint, they put a cat among the pigeons.
Hamilton survived a brief scare when a slow first stop meant he rejoined literally only feet ahead of Rosberg and Vettel, just as his team mate was diving down the inside to repass the Ferrari going into Turn 1. It looked close, but nobody hit anyone.
Thereafter, Hamilton went his own way, gradually pulling away from Rosberg, who was being shadowed by Vettel. But Raikkonen was very fast on his medium tyres and reeled all three in, taking the lead as they made their final stops, Vettel on lap 32, Hamilton on 33 and Rosberg on 34. By lap 40, however, Raikkonen's mediums were finished, and he had lost the lead to Hamilton that lap just before he pitted for a fresh set of softs.
He emerged well down on the lead fight, but his pace was sensational as he regularly slashed two seconds a lap from those in front. With two laps to go he had closed completely on Rosberg, but just as the tremendous pursuit reached its climax, the Mercedes driver's brakes faded going into Turn 1 and Raikkonen was able to simply slip by.
Suddenly even Hamilton looked vulnerable, with the Briton suffering his own brake issues on the final lap. Raikkonen pushed on, but eventually fell just 3.3s short of denying the defending world champion a second Sakhir victory.
Vettel should have been in the middle of all this, but on lap 35 he ran wide at Turn 15 and damaged his front wing as he fought to stay out of the gravel. That obliged him to make a third stop, which dropped him behind Bottas and, try as he might, he couldn't muster the speed to overtake. Bottas held on to fourth, with Vettel just one second down the road at the flag.
Ricciardo had a lonely race to sixth and was lucky to secure that given that his Red Bull's Renault engine blew as he exited the final corner. Grosjean also had a quiet run but was happy with another seventh for Lotus ahead of feisty Perez, who had many battles on his way to a useful eighth for Force India.
Kvyat had an up and down run to ninth, but it wasn't as hard as Felipe Massa's journey to 10th. The Brazilian's Williams stalled on the formation lap and he had to fight back from a pit-lane start throughout the evening.
Jenson Button's McLaren quit even before the start with more electrical problems centred around its energy recovery system, and though they might have been able to fix it Honda took the decision to withdraw the machine. Fernando Alonso drove the wheels off his MP4-30, but didn't quite have the pace to secure the alliance's first point; he missed tenth by a hair under four seconds.
Felipe Nasr was in the hunt for a while before his Sauber lost pace, but he finished ahead of Nico Hulkenberg's Force India and team mate Marcus Ericsson, who lost a load of time with a sticking left front wheel during his second pit stop on the 25th lap.
Pastor Maldonado was penalised five seconds for starting out of grid position, but drove well to get into a point-scoring position until the anti-stall kicked in during his second stop, on the 41st lap, and the engine cut out. He still finished ahead of the ever-reliable Marussias of Will Stevens and Roberto Merhi, however, which took 16th and 17th.
It was a tough day for Toro Rosso meanwhile, as both Carlos Sainz and Max Verstappen retired, neither having been in contention for the points.
In the championship standings, Hamilton now has 93 points to Rosberg's 66, Vettel's 65 and Raikkonen's 42, while Mercedes have 159 to Ferrari's 109 and Williams' 61.