O'Shea, 28, spent four years with Chesterfield, scoring 36 goals in 173 appearances after joining from MK Dons.
He joined Sheffield United on loan in January and scored three goals in 10 appearances, helping them finish top of League One.
"It's been a long time coming and it's meant some hard work, but it's been worth it," Bury manager Lee Clark said.
"He's had a lot of interest from other clubs after having a fantastic end to the season with League One champions Sheffield United."
O'Shea is Bury's eighth summer signing, following the arrivals of Jermaine Beckford, Phil Edwards, Stephen Dawson, Callum Reilly, Joe Skarz, Adam Thompson and Eoghan O'Connell.
Find all the latest football transfers on our dedicated page.
Bury have signed attacking midfielder Jay O'Shea on a two-year deal after his contract with Chesterfield expired.