The openside flanker was previously club captain at the Rec but has found his opportunities limited in recent seasons due to the presence of Francois Louw.
With England's Sam Underhill swapping Swansea for Bath this summer, his chances were expected to become even rarer and he has now moved west to South Wales.
At 27, Mercer still has some of his best years ahead of him and is looking forward to battling for the number seven shirt at the Liberty.
"It's a really exciting opportunity," said Mercer. "I'm really looking forward to it. It came a little bit out of the blue but that's rugby, professional sport, you have to just roll with it and take these opportunities when they come your way.
"I've been at Bath all my career, grew up supporting them, but this is another challenge for me. I'm excited about what's in store for me this season with the Ospreys and grateful for the opportunity."