Hereford avenged their defeat to Barnet earlier in the season with an exciting win at Edgar Street.
The Bees could have been 3-0 up by half-time had Giuliano Grazioli not wasted a string of chances.
The visitors were then made to pay after the break when Ben Smith drilled the ball past goalkeeper Robert Burch.
Grazioli then missed another sitter to equalise, before Danny Thomas clinched victory for Graham Turner's side with a powerful strike in the dying moments.
Hereford: Brown, McClenahan, Beckwith, Rose, Travis (Williams 27), Purdie, Smith, Jennings (Ferrell 46), Thomas, Connell (Sills 85), Guinan.
Subs Not Used: Lewis, Gulliver.
Goals: Smith 48, Thomas 90.
Barnet: Burch, Devera, Yakubu, King, Gross (Nicolau 69), Puncheon (Allen 76), Bailey, Lewis (Warhurst 74), Sinclair, Graham, Grazioli.
Subs Not Used: Flitney, Hendon.
Referee: D Deadman (Cambridgeshire).