Bayern edged a win against a brave Mainz side but were denied lifting the title by results elsewhere.