MELBOURNE, Australia (AP) — Defending champion Roger Federer admitted he was lucky to escape with a victory at the Australian Open on Wednesday, edging Gilles Simon 6-2, 6-3, 4-6, 4-6, 6-3 in the second round.

Early on it seemed as if Simon, who had beaten Federer in their only two previous meetings, would send the Swiss star packing out of a Grand Slam before the third round for the first time since the French Open in 2003 — a total of 31 majors.

Simon is one of only three players on the ATP Tour to hold a winning record against Federer, whose victory came on a day when one of the other stars of the tournament — fourth-seeded Venus Williams — nearly had to withdraw with a hip injury after the first set of her match. Williams recovered to advance to the third round with a 6-7 (6), 6-0, 6-4 win over Sandra Zahlavova of the Czech Republic.

The usually reserved Federer pumped his fist in celebration with each point in the final few games. He broke Simon's service in the sixth game of the deciding set to go up 4-2, held his service to go up 5-2, then held his serve two games later to clinch it with an ace on his fifth match point.

"I remained positive ... it paid off. I got lucky. I'm happy I'm still in the tournament," Federer said.

"I wasn't playing poorly in the third and fourth set, but Gilles took it to me. Clearly, he's a great player first of all. Matches against him don't come easily ... hopefully we don't play each other anymore!"

Simon said he needed "time to get used to (Federer's) game," which helped him win the third and fourth sets.

"It's going fast, he's moving fast, it's just impressive," Simon said. "There are not too many players able to play to this level."

Williams seemed to have the narrowest escape. Writhing in pain and clutching the inner hip area as she walked back to her courtside chair, she took a medical timeout after losing the first-set tiebreaker. She appeared to be on the verge of retiring, but a few minutes later she returned with her upper right thigh taped. Williams, who has never retired from a major, said she injured the muscle that flexes the hip and spinal column.

Roddick fired his 17th ace to finish off a 7-6 (7), 6-2, 6-3 second-round win over Igor Kunitsyn of Russia. He is into the third round at Melbourne Park for the ninth straight time.

His U.S. Davis Cup teammate Mardy Fish made a second-round exit, the No. 16 seed losing 1-6, 6-3, 6-3, 6-3 to Tommy Robredo. And ninth-seeded Fernando Verdasco rallied from two sets down to beat Serbia's Janko Tipsarevic 2-6, 4-6, 6-4, 7-6 (0), 6-0, conceding just one point on his serve in the last set.

No. 3 Djokovic defeated Ivan Dodig 7-5, 6-7 (10), 6-0, 6-2. Djokovic, who beat Jo-Wilfried Tsonga in the 2008 final in Melbourne Park for his only Grand Slam title, is in career-best form.

He appeared comfortable all over the court against Croatia's Dodig, who nevertheless challenged Djokovic in the first two sets with a powerful serve and strong baseline shots. Djokovic answered with his own baseline winners into back corners on both sides, as well as cross court volleys on the odd occasion Dodig sliced to draw him to the net.

Wozniacki advanced with a 6-1, 6-0 win over American Vania King in the Danish player's first major as No. 1. The 20-year-old reached the third round for a 13th consecutive Grand Slam.

To get to the semis, Wozniacki might have to beat seven-time Grand Slam winner Henin, who returned from a nearly six-month injury layoff with a 6-1, 6-3 win over Elena Baltacha of Britain.

The pair could meet in the quarterfinals. Henin will have to get through a tough match against two-time major winner Svetlana Kuznetsova just to get past the third round. The 23-seeded Kuznetsova beat Dutch qualifier Arantxa Rus 6-1, 6-4.

"I have a lot of good memories, almost all good memories, from Melbourne," said Henin, the 2004 Australian champion and runner-up here in 2006 and last year, when she was returning from a career break from the tour.

No. 8 Victoria Azarenka, the 2010 quarterfinalist who lost to Serena Williams each of the past three years, beat Andrea Hlavackova 6-4, 6-4. Serena Williams is injured and not defending her title in Australia.