The Red Dragons grabbed three precious points in a League Two clash that was scrappy but tense.
Michael Proctor scored the crucial goal in the 77th minute. Simon Spender crossed from the right for Proctor to give Darren Randolph no chance with a close-range effort.
The home side had to hang on desperately towards the end but first Proctor and then Stuart Nicholson came close with efforts that would have ended the tension.
Wrexham had to survive early pressure including six corners before, against the run of play, they took the lead in the 25th minute.
Sam Aiston picked up a clearance from one of those corners and raced a good 30 yards before firing in a shot which Randolph could only push out to Drewe Broughton who calmly scored.
Broughton hit the bar in the 44th minute but then came a disaster for the home side when Glynn Hurst headed an equaliser from Brian Barry-Murphy's free-kick.
Keeper Gavin Ward must take his share of the blame for the equaliser but he had earlier kept his side in the game with tremendous saves which kept out efforts by Andy Bishop and Elliott Bennett.
The Shakers opened the second half brightly but could have been behind when Broughton hit a shot straight at keeper Randolph from an Aiston cross.
Nicky Adams missed a chance for Bury from a few yards out with first Proctor and then Bishop netting only to be ruled offside.
Wrexham, who had already been hit by injuries, lost Neil Taylor and then Carl Tremarco, but the makeshift team managed to hold on to gain a win that will leave fellow strugglers looking over their shoulders.