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.
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.