MELBOURNE, Australia — An agitated Roger Federer spat out the question that Rafael Nadal and Maria Sharapova easily could have asked the players who pushed them to the limits in the second round of the Australian Open.

“Do you have to be that close?” Federer snapped at a TV cameraman hovering nearby as he received medical advice after losing a set Wednesday.

For Nadal and Sharapova, the nuisance was coming from the lowly ranked qualifiers across the net.

Nadal was taken to five agonizing sets by No. 112-ranked Tim Smyczek, who even did him a sporting favor in the last game of a 4-hour, 12-minute night match. Sharapova needed to save two match points before prevailing 6-1, 4-6, 7-5 against a fellow Russian, Alexandra Panova, ranked No. 150.

After his 6-2, 3-6, 6-7 (2), 6-3, 7-5 win, Nadal dropped to his knees on the court, clasping his hands in a prayer-like pose.

The 14-time Grand Slam champion has played some epic matches on Rod Laver Arena, including the 5-hour, 53-minute final he lost to Novak Djokovic in 2012, his championship win against Federer in 2009 and a myriad of painful encounters over the years.

The third-seeded Nadal came into the first major of the season after playing just four tournaments since Wimbledon because of a right wrist injury and appendix surgery.

Midway through the third set Wednesday, he needed medication for stomach cramps.

“At the end of the first set, I start to feel my body very bad, very tired … I was worrying crazy,” he said. “Then when I was serving for the third, almost throw up. So was terrible feeling.

“I was suffering a lot. Too much. Obviously is a very positive thing that finally I have the chance to win but yeah, I hope to recover myself.”

Federer was troubled by a sore right pinkie finger, an injury he couldn’t diagnose or explain, but rallied to beat Simone Bolelli 3-6, 6-3, 6-2, 6-2 to advance to the third round along with three-time Australian Open finalist Andy Murray, No. 7 Tomas Berdych and No. 10 Grigor Dimitrov.

“It felt like a bee stung me. I was like, ‘This can’t be possible, I never had this pain before.’ It was disturbing me,” said Federer, a four-time Australian Open champion. “I knew that to tape it wasn’t an option.”

Also, defending champion Stan Wawrinka advanced to the third round for the seventh consecutive year with a 7-6 (4), 7-6 (4), 6-3 victory against Romanian qualifier Marius Copil.

And the Williams sisters advanced to the third round, with top-ranked Serena fending off set points before going on a 10-game roll to beat Vera Zvonareva 7-5, 6-0 and Venus beating fellow American Lauren Davis in straight sets.

Kei Nishikori, a U.S. Open finalist, stayed on track for another strong Grand Slam performance when he beat Ivan Dodig 4-6, 7-5, 6-2, 7-6 (0) in the second round.