Gary Cahill's own goal gifted City the lead, but Costa equalised and teed up substitute Willian before Eden Hazard struck to send Antonio Conte's men four points clear of City at the summit.
City's frustration boiled over in stoppage time with Aguero and Fernandinho red-carded, the former for a disgraceful lunge on David Luiz, the latter for pushing Cesc Fabregas over an advertising board.
It was the second time in succession that Chelsea had come from behind to win, having done so against Tottenham Hotspur last weekend, as they recorded their eighth successive victory.
Pep Guardiola tasted defeat at the Etihad Stadium for the first time as City manager and has now seen his side go four home games without a win.
They were left to rue some profligate finishing, but it was referee Anthony Taylor who attracted the home fans' ire after rejecting four penalty appeals.
A muscular injury sustained by Nemanja Matic forced Conte to change his starting XI for the first time in seven games, with Fabregas coming into the team in central midfield.
Guardiola showed his respect for Chelsea's recent run by mirroring the Londoners' shape with a back three of his own, as he made six changes from last weekend's 2-1 win at Burnley.
Chelsea were given encouragement in the early stages, Hazard curling wide and failing to exploit a situation that saw him round City goalkeeper Claudio Bravo.
But as the half wore on, so City began to pin their opponents back and so Taylor became an increasingly central figure.
He had already denied City what would have been a very harsh penalty for handball against Cahill when Cesar Azpilicueta's under-hit back-pass gifted Aguero a run on goal.
De Bruyne miss
Luiz leant into Aguero as the Argentine sought to run past him, sending him crashing to the deck, but Taylor waved play on to the fury of the home support.
Shortly before half-time, Ilkay Gundogan appeared to be caught by N'Golo Kante as he shaped to shoot from Aguero's lay-off, but again Taylor was unmoved.
City had offered the greater threat, with Aguero threatening on three occasions, and the final minute of the half yielded the breakthrough.
Allowed to advance to the edge of the Chelsea box, Jesus Navas dispatched a pacy cross that Cahill contrived to shin past Thibaut Courtois.
Forced into an early change in the second half as Pedro Rodriguez succumbed to an earlier knock, with Willian coming on, Chelsea appeared at risk of being submerged.
Courtois saved from Kevin De Bruyne and David Silva, while Cahill had to slide in and clear after Aguero intercepted Marcos Alonso's back-pass and rounded Courtois.
De Bruyne then gave Chelsea an extraordinary let-off, slamming the ball against the bar from five yards after being picked out by Navas.
A goal seemed a matter of time and so it proved, but it was Chelsea who struck, Costa chesting down Fabregas's pass, holding off Nicolas Otamendi and drilling in his 11th goal of the campaign.
He played an instrumental role as Chelsea took the lead 10 minutes later, freeing Willian to run through and plant a low shot past a flat-footed Bravo.
City saw another penalty call waved away after Alonso swiped the air in front of Navas before Hazard made the game safe, racing onto Alonso's pass and coolly beating Bravo.
It proved the cue for a stoppage-time meltdown that will land Aguero and Fernandinho in hot water with the Football Association.
Original source: Costa keeps Chelsea flying as Man City lose their cool