City dominated early on and Ilkay Gundogan put them ahead on 27 minutes with a header from Fabian Delph's cross.
But by 35 minutes the match had turned on its head as Jeffrey Schlupp equalised then Townsend hit a stunning left-foot volley from outside the penalty area.
Luka Milivojevic added a third from the penalty spot six minutes after half-time, after a foul by Kyle Walker on Max Meyer.
Kevin De Bruyne pulled a goal back in the 85th minute with a cross that looped into the far corner.
But Palace hung on and 28 years to the day since Palace last won at City, they climb a place to 14th, on 18 points.
City stay second, four points behind Liverpool.
Man City: 26 Dec v Leicester City (A)
Crystal Palace: 26 Dec v Cardiff City (H)