Goals from Shaun Beeley, Shaun Harrad and Richard Hinds ensured the Shakers put their opening-day defeat behind them to clinch a place in the second round.
Crewe took the lead in the fifth minute when Chuks Aneke received a cut-back from Ajay Leitch-Smith and rifled the ball into the roof of the net.
But Bury equalised via a stunning goal from Beeley, who flashed in a stunning 20-yard effort into the corner of the net after 20 minutes.
The hosts then took the lead in the 29th minute, Harrad slamming home a penalty after Hinds had been fouled by Anthony Grant.
It got even better for Bury when Hinds poked home in the 49th minute after Crewe had failed to clear Craig Jones’ corner.
Crewe closed the gap with 15 minutes left, Harry Davis scoring from the penalty spot after Gareth Roberts had brought down Ryan Colclough.
But Kevin Blackwell’s side held on to reach the second round.