Struggling Crewe went in front when defender Jon Guthrie deflected in Marcus Haber's effort.
Barnsley levelled after Sam Winnall fired in from Conor Hourihane's corner.
Alfie Mawson won the game for the Tykes with a 20-yard free-kick after the hour, finding the top corner beyond Crewe goalkeeper Ben Garratt.
Barnsley fought back against Crewe Alexandra to make it nine wins from 11 games and close in on the League One play-off places.