Roger Federer celebrates after he won his match against German Daniel Brands at the German Open ATP tennis tournament in Hamburg Wednesday July 17, 2013. (Photo: AP)
The four-time Hamburg champion is playing his first tournament since losing in the second round of Wimbledon.
Federer won only three of 13 break points and needed six match points to close out the match. He did it with his seventh ace, shortly after producing a spectacular overhead smash winner with a flick of the wrist while stepping back in the final game.
The 17-time Grand Slam champion needed five set points to end the first set, finally earning it when Hajek netted a forehand.
Federer has dropped to No. 5, his lowest ranking in a decade. He will Florian Mayer of Germany, who beat 11th-seeded Feliciano Lopez of Spain 7-6 (1), 6-2.
Second-seeded Tommy Haas also advanced after beating Carlos Berlocq of Argentina 6-2, 6-4.
The German led 5-2 in the second set but dropped serve. He then wasted two match points on Berlocq's serve before using his fourth to close out the second-round encounter, hitting a cross-court forehand winner. Berlocq won his first title last week in Bastad, Sweden.
Juan Monaco, the fifth-seeded Argentine who beat Haas for the Hamburg title last year, defeated ninth-seeded Benoit Paire of France 6-3, 2-6, 6-2.
Haas will plays Fabio Fognini of Italy, who beat Marcel Granollers of Spain 6-2, 6-4. Fognini won his first title last week in Stuttgart and beat Haas in the quarterfinals.
Monaco plays third-seeded Nicolas Almagro, who beat Guillermo Garcia-Lopez 6-2, 6-3.
Fourth-seeded Wimbledon semifinalist Jerzy Janowicz of Poland was forced to retire with a right arm injury, allowing 14th-seeded Fernando Verdasco to advance. The Spaniard, who was leading 7-5, 4-0, will play Argentine qualifier Federico Delbonis, who beat Dmitry Tursunov of Russia 6-4, 6-3.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO Sports and on Facebook at AhramOnlineSports)