City suffered a first home league defeat of the season and had Aymeric Laporte sent off, the defender having earlier committed the error that gifted Zaha his sixth-minute opening goal, his 50th in the league for Palace.
Spain international Laporte struggled to deal with the Eagles' star forward and was caught out again in first-half stoppage-time, denying Zaha a goal-scoring opportunity as the last man with a clumsy challenge and being shown a red card.
Gallagher put the result beyond doubt with two minutes of normal time left to play, emphatically finishing off a counter-attack after good work from Zaha and Michael Olise.
Zaha gave Palace a shock early lead as Gallagher caught Laporte on the ball at the back before finding the Ivory Coast forward, who scuffed a low shot beyond Ederson and into the bottom-right corner.
City struggled to find its rhythm for most of the first half and Laporte's afternoon went from bad to worse just before the break as the centre-back was shown a straight red card for hauling Zaha down as the Eagles forward was set to go clean through on goal.
The hosts thought they had drawn level on the hour mark as substitute John Stones, a minute after his introduction, picked out Phil Foden with a terrific raking pass and the 21-year-old clipped a ball to the back post where Jesus squeezed home from a tight angle, but the goal was ruled out for a marginal offside after a video assistant referee (VAR) check.
City pushed for an equaliser in the remaining half-hour, but Palace remained resolute and stung the hosts in the 88th minute. Zaha held the ball in the box before squaring to Olise, who laid it off for Gallagher with one touch, allowing the midfielder to thump into the top-right corner and ensure Guardiola's landmark game ended with the Spanish boss empty-handed for once.