Doncaster snatched a stoppage-time winner to brush off a rally by struggling Barnet.
Barnet looked to have snatched a late point after coming back from two goals down.
But Andy Williams clipped home very late on to make it 3-2, a result which keeps Doncaster second in Sky Bet League Two.
Goals from James Coppinger and Matty Blair had given Doncaster a deservedly comfortable lead at the break.
But dogged and industrious Barnet rallied well, pulling a goal back through Bira Dembele before substitute Luke Gambin glanced home four minutes from time.
Such a dramatic finish could hardly have been predicted after a first half which Doncaster thoroughly dominated.
Coppinger left Barnet keeper Josh Vickers standing with a superb volley on 15 minutes before Blair drilled a low effort into the far corner on 32 minutes to make the dominance count.
Barnet rallied superbly after the break and pulled a goal back when Dembele flicked home Sam Muggleton's long throw.
With four minutes to go, Gambin hooked in a low centre.
But the drama was not over and Williams grabbed the winner for Doncaster when he darted to the near post and flicked in Blair's brilliant cross.