Using a bigger racket for the first time, Federer served three aces in the opening game but still lost his serve and ultimately the set to the German. The former No. 1 broke once in the second set and twice in the decider to reach the third round.
The 17-time major champion is a four-time winner in Hamburg, the city where he won his first title in 2002 to break into the top 10.
After losing at Wimbledon to Sergiy Stakhovsky -- who failed to qualify for the main draw in Hamburg -- Federer dropped to No. 5 in the rankings, the first time in a decade that he's been that low.
Brands, who celebrated his 26th birthday Wednesday and received a cake after the match, got few presents from the top-seeded Federer in the last two sets. However, the Swiss star needed four match points to close it out. He finished with nine aces on the clay-court surface.
"It was a tough match. Daniel is playing a very good season," Federer said.
Federer will play qualifier Jan Hajek of the Czech Republic, who beat 15th-seeded Ernests Gulbis of Latvia 6-4, 2-6, 6-4.
Tommy Haas outlasted qualifier Blaz Kavcic of Slovenia 6-1, 4-6, 6-4 to advance to the third round.
The second-seeded Haas blew a 4-1 lead in the third set but held serve and broke to clinch the match when Kavcic sent a forehand long.
"At the end, it's the victory that counts," Haas said.
Haas was runner-up in the tournament last year and is the oldest player in the top 100 at 35. He is looking for his second title at home this season, after winning in Munich.
Defending champion Juan Monaco of Argentina, seeded fifth, beat Gael Monfils 6-4, 6-4.
Four other seeded players lost -- No. 6 Andreas Seppi, No. 10 Tommy Robredo, No. 13 Mikhail Youzhny and No. 16 Martin Klizan.
No. 11 Feliciano Lopez, No. 12 Fabio Fognini and No. 14 Fernando Verdasco advanced.