Dale's unbeaten home record looked in jeopardy with Aidy Boothroyd's well-organised side leading 2-1 and proving tough to break down as the second half drew to a close.
But Michael Rose's 88th-minute free-kick and a neat finish from George Donnelly two minutes later turned the game on its head and handed Dale their fifth successive victory on home turf.
The visitors caught Dale cold with a stunning opening goal just 40 seconds in. Luke Norris, the striker on loan from Brentford, collected the ball 25 yards from goal and sent a dipping shot over Josh Lillis.
The Cobblers almost doubled their advantage when Darren Carter got the better of Oliver Lancashire and fired towards the bottom corner, Lillis at full stretch diving to his left to deny the Northampton captain.
Rochdale levelled on 26 minutes when a loose header from Paul Reid dropped invitingly for Ian Henderson and he drove a low shot wide of Matt Duke.
But Boothroyd's team regained the lead in the 38th minute when Carter fed Stuart Dallas and he raced clear down the right before flashing a fierce effort past Lillis.
Dale were unable to break down a well-organised Northampton side until Rose sent a low free kick round the side of the Cobblers' wall and inside Duke's near post.
And the hosts were not finished there, Donnelly racing through the middle and firing home the winner as the game entered time added on.