Craig Davies' 79th-minute goal saw Barnsley leading 2-1 in the first-round tie at Spotland after 90 minutes when goalkeeper Alnwick was sent off for aiming a headbutt at Ray Putterill.
Alnwick had hold of the ball when he needlessly hit out at the Rochdale man, earning a straight red card from referee Gary Sutton.
His moment of madness presented Jason Kennedy with the opportunity to level the tie from the spot, beating full-back Bobby Hassell in the Barnsley goal.
But Dagnall's classy brace in the first half of extra-time put the visitors in the driving seat.
A second Kennedy penalty - following a hand ball offence by Jim McNulty - kept the hosts hopes alive.
However, the Tykes hung on, Hassell saving brilliantly from Kennedy and Ryan Edwards to hand former Rochdale boss Keith Hill a winning start to his second season as Barnsley manager.
Andrew Tutte had fired Rochdale ahead just six minutes into the game, curling a perfectly flighted shot over Alnwick and into the net from 20 yards.
Despite bossing the first half, Rochdale were pegged back just before the break when John Stones headed Jacob Mellis' free-kick wide of Josh Lillis in the hosts' goal.
Davies appeared to have decided the tie on 79 minutes when he turned Phil Edwards on the edge of the area and stroked home, until Alnwick's moment of madness took the tie into extra-time.