George Moncur bagged a brace as 10-man Barnsley beat Yorkshire rivals Bradford 2-1 to reach the Checkatrade Trophy knockout stages.
The Reds’ unbeaten run at Oakwell, which dates back to March 30, was under threat as on-loan Rotherham forward David Ball fired struggling City into an early lead.
But the Tykes grew into the game and a goal in each half from Moncur ensured Daniel Stendel’s side finished top of Northern Group F.
Not even a second yellow card for Adam Jackson late on could not stop Barnsley, who won this competition the last time they competed in it in 2016.
With Stendel using the Trophy to give his fringe players increased game time, he made 11 changes from Saturday’s FA Cup rout of Notts County.
But the German’s new line-up did not start well and, having almost let Sherwin Seedorf in, found themselves behind in the eighth minute.
Ball produced a classy finish, curling an effort past Jack Walton after receiving a pass from Kai Bruenker.
Barnsley refused to be downhearted and almost hit back immediately as Moncur fired into the side-netting.
Visiting goalkeeper Richard O’Donnell saved another shot from Moncur, who then made it third time lucky to get his side back on level terms.
The former Colchester midfielder, unmarked on the penalty spot, was on hand to convert Dani Pinillos’ cross with a sublime first-time finish in the 28th minute.
Walton prevented Bradford from going ahead for a second time, producing a fine save to keep out Ball’s free-kick.
At the other end, O’Donnell was called into action shortly before half-time to repel Jordan Williams’ shot from the edge of the area.
Walton denied Bradford again on the hour mark, acrobatically tipping a deflected Ball strike away for a corner, before Bruenker had a goal ruled out for offside.
But Barnsley made them pay just five minutes later as Moncur produced a fine turn and finish following a flowing counter-attack down the left that involved Pinillos and Ryan Hedges.
Moncur was full of confidence and almost secured the match ball, curling an effort just wide as the hosts looked to put the game to bed.
A mix-up at the back nearly cost Barnsley, which came from Walton diving on a back-pass, but Jack Payne’s six-yard in-direct free-kick cannoned back off the crossbar.
The hosts had to survive a late onslaught after Jacksonsaw red for a tackle on Bruenker in the 77th minute.
Debutant Will Smith blocked substitute George Miller’s shot and Anthony O’Connor blazed over for Bradford.
Barnsley: Walton, J Williams, Jackson, B Williams, Pinillos, Bird, Bahre, Brown (Isgrove 72), Moncur (Smith 78), Hedges, Adeboyejo (Helliwell 87).
Subs: Greatorex, Otim, Feeney, Fielding.
Bradford: O’Donnell, Chicksen, J O’Brien (L O’Brien 46), O’Connor, Payne, Seedorf (Wood 56), Bruenker (Miller 76), Knight-Percival, Devine, Ball, Wright.
Subs: Wilson, McGowan, Doyle, Isherwood.
Referee: Carl Boyeson