All the early pressure came from the home side but they were unable to create a clear-cut chance, and it was the relegation-threatened visitors who took a shock lead after 21 minutes.
Mark Byrne played the ball down the right flank and Jake Hyde timed his run to perfection to beat the offside trap and calmly lob the ball into an empty net after Rotherham goalkeeper Andy Warrington had raced off his line.
Seven minutes later Ibra Sekajja's shot was tipped over the bar by Warrington, and from Byrne's resulting corner Andy Iro's header was cleared off the line.
In six minutes of added time, Barnet's goal led something of a charmed life as a Johnny Mullins shot was cleared away from danger before Graham Stack made a fantastic double save to twice keep out headers from Ian Sharps.
Two substitutions early in the second half made little difference for Rotherham, although loan signing Daniel Kearns set up a chance for Kayode Odejayi but he headed wide from three yards out.
And eight minutes from time Rotherham were undone for a second time when Ricky Holmes beat his man wide on the left and squared a perfect ball for substitute Andy Yiadom to sweep home an unmissable chance.
Source: PA
Source: PA