ELBOURNE, Australia -- Defending champion Roger Federer admitted he was lucky to survive a major scare at the Australian Open on Wednesday, beating Gilles Simon 6-2, 6-3, 4-6, 4-6, 6-3 in the second round.

For a while, 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 the Swiss star, although Federer cut the margin. Simon's series lead is now 2-1.

Federer's win 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, but recovered to advance to the third round.

Federer, pumping his fist increasingly in celebration with each point in the final few games, 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 again held his serve two games later to clinch it on his fifth match point with an ace.

"I'm happy I survived a scare like today. It's not the first time," he said. "It does happen, and you just try to stay calm even though I'm not playing for much. He's playing for the huge upset, and I'm just trying to get through. So it's not easy."

Federer said he remained positive.

"It paid off. I got lucky. I'm happy I'm still in the tournament," the 16-time major winner 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 also had some drama getting through to the third round, overcoming a painful injury to beat Sandra Zahlavoa of the Czech Republic 6-7 (6), 6-0, 6-4.

Novak Djokovic, Andy Roddick, top-seeded woman Caroline Wozniacki, last year's finalist Justine Henin and 2008 champion Maria Sharapova also advanced.

Williams seemed to have the narrowest escape. Writhing in pain and clutching near her stomach as she walked back to her courtside chair, a WTA trainer was called and Williams took a medical timeout after the first-set tiebreaker. She appeared to be on the verge of retiring, and certainly was on the verge of tears. But a few minutes later, she returned with her upper right thigh taped and later said she injured her "psoas" muscle, which flexes the hip and spinal column. That maintained her record of never retiring in a major tournament.

No. 3 Djokovic beat 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.

Djokovic will next play his Davis Cup teammate Viktor Troicki after the 29th-seeded player beat Frenchman Nicolas Mahut 6-4, 6-2, 1-6, 6-3.

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 continued her comeback from injury 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.

In other matches, Barbora Zahlavova Strycova of the Czech Republic beat Australian wild card Jelena Dokic 7-6 (3), 6-1, and No. 9 Li Na defeated Evgeniya Rodina of Russia 6-3, 6-2.

On the men's side, Wimbledon finalist Tomas Berdych needed four match points to beat Philipp Kohlschreiber 4-6, 6-2, 6-3, 6-4, and eighth-seeded Roddick fired his 17th ace to finish off a 7-6 (7), 6-2, 6-3 second-round win over Igor Kunitsyn of Russia. The former No. 1-ranked Roddick is into the third round at Melbourne Park for the ninth straight time.

"When you're confident, the court just makes sense; decisions come easier to you," he said.

Roddick's 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.