The Bulldogs trailed 36-22 with just six minutes remaining but scored three late tries to snatch victory.
Matthew Hadden was sin-binned for holding down and from the resulting penalty, a long pass out wide sent Shaun Ainscough over for a try which gave the Bulldogs hope.
Ainscough then grabbed his second try in as many minutes and Dominic Brambani landed a towering touchline goal to reduce the deficit to four points.
With just two minutes remaining, Brambani broke through and sent Tom Lillycrop storming to the line and Brambani converted to complete the thrilling win.
Rochdale had built a commanding 16-0 lead before Macauley Hallett replied with an unconverted try for Batley but Rochdale responded again.
Sam Smeaton stretched over for the Bulldogs and Rochdale then had Jonathan Smith sin-binned and Brambani produced a lovely chip over Hallett to gather and score as Batley went into the break trailing 22-12.
Rochdale extended their lead still further, with Bulldogs prop James Brown sin-binned for a high tackle on Gary Middlehurst. Smeaton capitalised on Batley pressure with his second try wide on the right and Will Maher then surged over from 10 metres out and Brambani landed his first goal before the late drama.
Batley Bulldogs: Hayward; Reittie, Smeaton, Hallett, Ainsough; Holmes, Brambani; Rowe, Leak, Maher, Day, Harrison, Chandler. Subs: Davey, Lillycrop, Brown, Hill.
Rochdale Hornets: Johnson; Eccleston, Jullien, Galbraith, Massam; Livett, Yates; Taira, Maneely, Bennion, Smith, Savelio, Middlehurst. Subs: Moores, Tahraoui, Hadden, Case.
Referee: Callum Straw.