The 31-year-old former England international made his debut for Bath back in 2006 and has gone on to make over 250 appearances for the club.
Powerhouse wing Banahan, who can also play in the back three or in midfield, has agreed to match the switch to Kingsholm at the conclusion of this campaign.
Gloucester director of rugby David Humphreys said: "Matt has had a wonderful career at Bath and he will bring a huge amount of quality and experience to the young, exciting squad we are building in Gloucester.
"His versatility and ability to play in a number of positions across the backline adds real depth to our squad and Matt's quality will complement the style of rugby Johan Ackermann has brought to the club this season.
"I know how tough a decision it was for Matt to leave Bath but we're all looking forward to seeing him playing in Cherry and White next season."
Bath director of rugby Todd Blackadder said: "We'll be really sad to see Matt leave at the end of the season, but we completely understand the decision he has made with his family and future in mind.
"I'd like to thank him for all his efforts over the years – he's been a fantastic servant for Bath. Everyone at the club wishes him well with the next chapter of his career and will welcome him back to the Rec when the time comes.
"I've no doubt he'll remain as committed as ever as we work to achieve our aims for the rest of the season.
"We're working hard to ensure we get the right balance in the squad, taking into account the various complexities of building the squad we want long-term, and we will make further announcements on recruitment when appropriate."
Gloucester sits one place and one point above Bath in the table, residing in fourth.