Papiss Cisse scored in the last second of the tie to send Newcastle into the quarter-finals of the Europa League.
The Senegal striker headed in Sylvain Marveaux's cross three minutes into injury time to break the stalemate.
Anzhi Makhachkala were reduced to 10 men when Mehdi Carcela-Gonzalez picked up two yellow cards in seven minutes at the start of the second half.
They almost won it when Mbark Boussoufa's free-kick hit the crossbar, six minutes before Cisse's winner.
Europa League quarter-finalists
Chelsea, Newcastle United, Tottenham Hotspur
Quarter-final draw to be made on Friday.
It was a dramatic finale to a gripping second leg at St James' Park that was finely poised after
Newcastle ground out a goalless draw in Moscow.
Newcastle's best chance had come moments before Carcela-Gonzalez's red card when defender Steven Taylor shot straight at keeper Vladimir Gabulov from six yards.
And Anzhi had the better chances once they were down to 10 men.
Champions League winner Samuel Eto'o, who was a constant menace, drilled in a near-post shot from a tight angle that was palmed away by stand-in keeper Rob Elliot.
Elliot was then beaten by Boussoufa's delightful 20-yard set-piece in the 88th minute and was relieved to see it bounce back off the woodwork.
The result backed up Alan Pardew's pre-match rallying cry that his side could give the competition "a good go".
With Newcastle pulling nine points clear of the Premier League relegation zone, the Magpies boss named arguably his strongest starting line-up of the competition so far and included nine players that played in
the win over Stoke at the weekend.
But the expensively-assembled Anzhi were a big improvement on the side that had laboured to a draw in Russia despite being without influential playmaker Willian, who limped out of the action last week.
Eto'o hit an early strike before teeing up a chance for former Real Madrid and Portsmouth midfielder Lassana Diarra, whose shot was blocked by Taylor.
Newcastle's only first half threat came from long range with only Yohan Cabaye testing Anzhi keeper Gabulov with a deflected strike.
But the Frenchman, who has suffered with injury all season, was hit with another setback midway through the half and was replaced by Jonas Gutierrez.
However, the game was turned on its head eight minutes into the second half when Carcela-Gonzalez, who had picked up the first yellow card of the night moments after the restart, followed it up with a second for a clumsy, late challenge on Massadio Haidara.
Newcastle tried to remain patient but the game looked like it was heading for another 30 minutes of extra-time until Cisse's dramatic late goal.
Newcastle manager Alan Pardew:
"We did a lot better in the second half and put them under pressure and when you put them under pressure something gives.
"I think we've put out one of the best teams in the competition if I'm honest.
"We just squeezed over the line and I'm highly delighted. We've had a very, very tough two games."
Anzhi Makhachkala manager Guus Hiddink:
"We created, against a Premier League team, four or five open chances. We can blame ourselves (for missing them).
"It was not a wise action what (Mehdi Carcela-Gonzalez) did, but (the red card) was harsh.
"The referee was maybe a little bit influenced by the crowd."
- 21 Elliot
- 03 Santon
- 13 Yanga-M'Biwa
- 27 S Taylor
- 35 Haidara
- 04 Cabaye (Gutierrez - 37' )
- 07 Sissoko
- 08 Anita Booked (Campbell - 71' )
- 22 Marveaux
- 24 Tiote
- 09 Cisse
- 37 Harper
- 14 Perch
- 18 Gutierrez
- 20 Bigirimana
- 25 Obertan
- 23 Sh Ameobi
- 49 Campbell
- 01 Gabulov
- 02 Yeschenko
- 05 Carlos
- 37 Ewerton
- 06 Boussoufa
- 08 Jucilei
- 16 Gonzalez Dismissed after an earlier booking
- 18 Zhirkov Booked
- 25 Ahmedov
- 85 Diarra (Shatov - 74' )
- 09 Eto'o
- 22 Pomazan
- 13 Tagirbekov
- 15 Logashov
- 07 Agalarov
- 14 Shatov
- 19 Traore
- 20 Smolov
Ref: Deniz Aytekin