Elsewhere, Manchester United won 1-0 against Crystal Palace on Juan Mata's goal to climb provisionally to sixth, West Ham drew 0-0 at home to Aston Villa and Burnley recorded their first win in the league this season - 1-0 against Hull.
At Anfield, Liverpool manager Brendan Rodgers made seven changes from the side that lost 1-0 to Real Madrid in the Champions League on Tuesday.
His midweek selection was criticised as he appeared to prioritise the clash against Chelsea, and the gamble looked as if it could pay off as Liverpool took the lead when Can's long-range strike deflected in off Cahill.
Chelsea equalised with a goal that required confirmation from goal-line technology, with Cahill blasting a shot from close range that goalkeeper Simon Mignolet saved before falling back over the line with the ball in his hands.
Costa's winner came when he pounced on the rebound after Cesar Azpilicueta's shot was parried out by Mignolet.
City fell behind at Loftus Road in the 21st when Charlie Austin converted from Mauricio Isla's cross. Austin earlier had two goals disallowed, one for offside and one after scoring directly from a mis-hit free kick by goalkeeper Joe Hart.
Hart accidentally kicked the ball twice before Austin found the net, and rules state a player cannot touch the ball twice successively from a free kick.
Aguero equalised after brilliantly controlling a long pass from Eliaquim Mangala, but an own goal from Martin Demichelis in the 76th restored QPR's lead.
Argentina striker Aguero scored again seven minutes later, rounding Robert Green before beating four players on the line attempting to block his shot.
"Aguero had all the QPR defence in trouble whenever he had the ball," Pellegrini said, while QPR manager Harry Redknapp was left ruing his side's inability to hold on for victory.
"I really felt at 2-1 we would go on and win the game," Redknapp said.
United earned a much-needed three points over Crystal Palace at Old Trafford thanks to Mata, who struck a deflected shot, beating goalkeeper Julian Speroni four minutes after coming on as a replacement for Adnan Januzaj in the 63rd.
But it was another underwhelming performance from Louis van Gaal's team, which started with a makeshift defence that had midfielder Daley Blind and 19-year-old Paddy McNair at centreback with four alternative options injured or suspended.
The victory - United's first in four attempts - saw them overtake fierce rival Liverpool in the standings.
Southampton continued their formidable start to the season courtesy of two goals in five minutes from Shane Long, who broke the deadlock in the 75th, before finishing clinically past the Leicester goalkeeper for his second.