A first Russian league goal for Italian veteran Claudio Marchisio put Zenit into the lead but Anzhi’s Venezuelan forward Andres Ponce and Vladislav Kulik scored one apiece to record a well-deserved win.
Zenit remain top of the table, three points clear of second-placed Krasnodar, who thrashed Dynamo Moscow 3-0.
Rostov, who edged Spartak Moscow 1-0, sit third, one point further back.
Marchisio broke the deadlock two minutes after the interval after a shot by Sebastian Driussi hit the woodwork and bounced back into play.
Ponce pulled the scores level after 71 minutes, firing the ball home with an angled close-range shot.
In the 76th minute, Anzhi skipper Dmitry Belorukov received a red card but Zenit failed to capitalise on their numerical advantage before Kulik scored the winner from the spot with seven minutes to go after Roland Gigolayev was fouled in the area.
“We’re in a difficult position and every win is precious for us,” Anzhi head coach Magomed Adiev said.
For Krasnodar, Brazilian striker Ari opened the scoring in the 18th minute before Swede Viktor Claesson added a second in first-half injury time.
Claesson rounded off the scoring in the 55th minute when netted his second of the match from a right-wing cross by Wanderson.
“It was our third match this week but we played very good football today,” Krasnodar acting manager Murad Musaev said.
In Sunday’s late game, former Chelsea and England star John Terry was in the crowed to see Spartak face Rostov. Last month Terry rejected the offer to join Spartak for family reasons.
In the 67th minute, Rostov grabbed the only goal when Timofei Kalachev found the unmarked Alexander Zuev who scored at the second attempt.
“We wanted to win and everything worked well for us today,” said Rostov head coach Valery Karpin, who coached Spartak between 2009-2014.
“I’m pleased with the result but we still have plenty of home work to do.”
For more news your way, download The Citizen’s app for iOS and Android.
Download our app and read this and other great stories on the move. Available for Android and iOS.