Ribery sends Bayern top
The Frenchman burst down the left, cut inside his marker and scored with a shot inside the near post in the 78th minute, only his third Bundesliga goal of an injury-plagued season.
The win moved Bayern onto 52 points from 24 games and took them two ahead of previous leaders Bayer Leverkusen, who were held 0-0 at home by Cologne on Saturday and lost top spot despite being unbeaten after 24 games.
Schalke 04, who beat arch-rivals Borussia Dortmund 2-1 on Friday, are a further two points behind in third place.
Hanover 96 finished the weekend in the relegation zone after they lost 1-0 at home to champions VfL Wolfsburg in Sunday's other game.
"It was an even match, Hamburg have very good players but a single player decided the match," said Bayern coach Louis van Gaal.
"I find it unbelievable that a team which hasn't lost does not lead the table but that says something about us," added the charismatic Dutchman.
Bayern appeared to be running out of ideas until Ribery struck.
The hosts made a lively start with Arjen Robben's runs down the right continually troubling the visitors. Mark van Bommel had a shot deflected wide and Thomas Mueller forced Frank Rost into a difficult save from a narrow angle in the first half hour.
Hamburg sounded their first warning when Piotr Trochowski fired over following a counter-attack while Mladen Petric should have done better just before halftime when his effort also flew over from a dangerous position.
Hamburg, fourth with 40 points, managed to frustrate the hosts for most of the second half.
Robben's runs became increasingly unproductive and predictable and Bayern's final passes repeatedly went astray.
Ribery looked the most dangerous, toe-poking one effort just wide before breaking the deadlock near the end.
Hanover slumped to their ninth defeat in a row as they dropped to 17th in the 18-team table with 17 points, one behind Nuremberg who drew 0-0 at VfL Bochum on Saturday to move into the relegation playoff spot.
The hosts had the better of the game but failed to take their chances and were punished by Zvjezdan Misimovic who turned in from close-range in the 78th minute.