Gary Cahill s own goal gave 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.
“I think today was very tough and the game was open until the end,” said Conte.
“I saw lots of character from my team and that s very important. We must continue to work and improve.”
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.
City were left to rue some profligate finishing, but although referee Anthony Taylor attracted the home fans ire for rejecting four penalty appeals, their own discipline let them down.
Aguero will now be banned for four games and Fernandinho for three.
“We didn t win because we missed a lot of chances. Not for the referee,” Guardiola said.
“It s a pity it finished like this. I don t like that. I apologise for what happened.”
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.
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.
De Bruyne miss against Manchester City
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.
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.
Initially, Chelsea appeared at risk of being submerged in the second half.
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 on the hour, 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. Cue City s meltdown.