Lionel Messi had given Barcelona the lead on the counter-attack after City were denied a penalty for a Samuel Umtiti challenge on Raheem Sterling.
Gundogan’s leveller came against the run of play prior to the interval.
Kevin De Bruyne’s 51st-minute set-piece fooled Marc-Andre ter Stegen to move City in front, before Gundogan wrapped up a first victory over the Catalan giants in six attempts 16 minutes from time.
And the hosts held on for the victory to extend their unbeaten home run in the competition to a club-record seven matches.
Barca, who remain top of the group, must now wait to book their place in the last 16.