The 29-year-old Australian won 3-6, 7-6 (4), 6-4 in his first final of 2010. Hewitt last beat Federer in 2003.
Top-seeded Federer, who was chasing his sixth title in Halle, Germany, had won his previous 29 matches at the Wimbledon warmup tournament.
It was Hewitt's first appearance at Germany's only grass court tournament.
After cruising through the previous four rounds without dropping a single set, Federer met his match in the battle between two former world number ones.
The Swiss started strongly and earned two breaks on Hewitt's first service game and appeared set to make light work of his sixth Halle final, taking the first set 6-3.
But Hewitt broke early in the second set, confirming he was willing to make a fight of it.
Federer broke back immediately and the game followed serve. Hewitt won the tiebreaker, converting his fourth set point to level the match and becoming the first player to take a set off Federer in Halle since 2006.
The final set belonged to the Australian, who broke again in Federer's first service game and never looked back. Hewitt took his first match point with a bit of fortune as the ball clipped the top of the net to end Federer's domination in Halle.
"It's fantastic," Hewitt said. "Roger is a hell of an opponent and everybody knows how good he is on the grass court. His record speaks for itself and I just got lucky."