Rotherham had dominated the first-half but went in level after Nicky Adams converted a late first-half penalty.
Rotherham started brightly with Pablo Mills and Mark Hudson both having long-range shots go wide.
They took the lead on 22 minutes with their first goal from a corner in more than a year.
Stephen Brogan swung over the set piece and Marc Newsham rose highest to steer the ball home via the post.
The goal sparked an exciting 20 minute spell when the hosts should have put the game out of reach.
Ryan Taylor unleashed a 25-yard drive that was well held by Jim Provett. Taylor then forced a brilliant save from Provett after racing on to a goal kick from Andy Warrington, who at this stage was a virtual spectator.
Then on 42 minutes Bury snatched an equaliser when Sharps was penalised for tugging back Glynn Hurst following a long throw from Dave Challinor.
Adams, who was Bury's best player, steered the ball into the top corner from the spot.
Bury started the second half the better side but 10 minutes in Rotherham broke at pace through Taylor. He fed O'Grady on the left and as he cut in his cross deflected off Steve Haslam and looped home over Provitt.
This again prompted an excellent spell of football from Rotherham, with Brogan missing the chance to double the lead moments later from a similar breakaway.
A great cross from Dale Tonge found Taylor but he could only steer his header wide.
Bury continued to be dangerous on the break as Andy Bishop set up Adams whose curling shot was saved.
Newsham and Taylor both missed good chances to put the result beyond doubt.
Lee Bullock and Domaine Rouse had Bury's best chances late on but their own unbeaten run of eight matches came to an end.