It was a game of two halves as City dominated the first 45 minutes and deservedly went 2-0 up with goals from Vincent Kompany and Ilkay Gundogan.
But it was a different United side that emerged for the second half as a brace from Paul Pogba and a Chris Smalling goal completed the remarkable derby turnaround.
It was City’s first home loss of the season and their second straight defeat following their 3-0 reverse to Liverpool in the UEFA Champions League on Wednesday.
David Silva had City’s first attempt on goal in the 20th minute after Paul Pogba was robbed of the ball in the middle but fired his effort way over the bar.
City eventually broke the deadlock on 25 minutes off Kompany’s bullet header from Leroy Sane’s corner.
In the 31st minute a poor clearance from David De Gea saw City go 2-0 up thanks to Gundogan who turned his marker beautifully inside the box from Raheem Sterling’s pass before poking the ball into the net.
Sterling should have made it three for City after he was played through on goal but shot over the bar with De Gea to beat.
Sterling was presented with another great opportunity on 36 minutes following a defence splitting pass but he once again shot over the bar with De Gea at his mercy.
With five minutes remaining in the first half, De Gea denied Sterling from scoring as he got down well to stop his left-foot low strike from Sane’s cutback.
United came with intent early in the second half and went close on 49 minutes but Ederson got down well to stop Pogba’s left-foot shot.
City responded with their own attack few minutes later but Gundogan’s clever curler clipped the edge of the post.
United pulled a goal back on 52 minutes as Pogba slotted the ball past the onrushing Ederson from a fine chest down from Ander Herrera.
Pogba was on target again on 54 minutes as he rose highest to head in Alexis Sanchez cross.
On the hour mark, Jesse Lingard went close with a left-foot strike which went just wide off target.
In the 69th minute, Smalling made it 3-2 as he stabbed in Sanchez’s delightful free-kick.
The game almost degenerated into a brawl as reckless tackles were flying around with Pogba, Sergio Aguero and Fernandinho all getting booked.
With less than 10 minutes left City almost drew level but Ashley Young made a timely clearance.
In the 89th minute De Gea made a world class save off Aguero’s header from Sane’s cross.
From the resultant corner Sterling saw his effort hit the post before De Gea cleared away for a corner.