Mercer, the son of New Zealand rugby league player Gary, has been capped by England up to under-20 level.
The 19-year-old has made 10 Premiership appearances for Bath, having made his debut against Newcastle in September.
"Zach is one of the brightest prospects in English rugby," director of rugby Todd Blackadder said.
"We are thrilled to have secured his services and he will undoubtedly be a huge asset over the next few years.
"He has shown maturity beyond his years in the way he has stepped up to the first team and he has taken full advantage of his opportunities."
Meanwhile, Bath have signed Plymouth Albion prop Sam Nixon, 20, on a deal running until 2019.
Nixon has been named among the replacements for Bath's game at Newcastle in the Anglo-Welsh Cup on Saturday.
Bath flanker Zach Mercer has signed a contract extension to stay with the Premiership club until the end of the 2018-19 season.