The Newcastle player struck from the spot in the 80th minute after Fernandinho had fouled Sean Longstaff.
It left City four points adrift of Liverpool, who face Leicester City on Wednesday.
City took the lead after just 24 seconds with Sergio Aguero's 15th PL goal against Newcastle.
But the home side hit back as Salomon Rondon levelled in the 66th minute, volleying in Isaac Hayden's header, before Ritchie held his nerve from the spot.
A first PL victory over City since 2005 moves Newcastle up to 14th on 24 points, five above the relegation zone.
Newcastle: 2 Feb v Spurs (A)
Man City: 3 Feb v Arsenal (H)