HALLE, Germany(AP) Novak Djokovic saved five match points, staving off Florent Serra 5-7, 7-5, 6-1 Thursday and advancing to the Gerry Weber Open quarterfinals.

The fourth-ranked Serb produced his best tennis when he was on the brink of defeat against the Frenchman, winning 11 of the last 12 games.

``For most people there would not be much left to do, but the lesson from today is to play until the last shot,'' Djokovic said.

Djokovic said the match reminded him of his Wimbledon second-round victory as a qualifier over Guillermo Garcia-Lopez in 2005, when he saved six match points to win in five sets. That victory allowed him to break into the top 100.

``That victory meant a lot to me back then and hopefully this one will do something as well,'' he said.

Djokovic will face seventh-seeded Jurgen Melzer, who advanced when Nicolas Kiefer retired with a stomach muscle injury after losing the first set 6-1.

Earlier, Andreas Beck became the fifth German into the quarterfinals of the grass-court tournament, defeating Lukas Lacko of Slovakia 7-5, 7-6 (5). Lacko was the lucky loser from qualifying who replaced top-seeded Roger Federer in the draw after the Swiss star withdrew after his victory at the French Open on Sunday.

Djokovic appeared headed for an early exit when he trailed 5-2 in the second set after an error-filled performance. Facing three match points on his own serve, Djokovic hit a volley winner, an ace, and service winner.

Djokovic faced more match points in each of the next two games, saving one with a drop shot and another ace on the next.

Serra, who had won one of their two previous meetings, thumped a forehand into the net to drop serve and gave Djokovic the set.

Serra's last chance to get back into the match came when he had two break points while trailing 4-1 in the third. But Djokovic unleashed another ace to hold serve and closed the match with another drop shot Serra pushed wide.