NEW YORK — Rafael Nadal withstood his first test at this U.S. Open, shifting into another gear to beat Sam Querrey 6-2, 5-7, 7-6 (2), 6-3 Monday and match his best result at the tournament that's always bedeviled him.

Playing for the sixth year at Flushing Meadows, the No. 1 Nadal rallied to reach the quarterfinals. He got quite a workout — and a scare — from his unseeded, 20-year-old opponent.

"Very tough," Nadal said. "Sam is a big player, a big server. He has a great future."

Down 6-5 in the third set, Nadal suddenly flashed the form that won at Wimbledon, the French Open and the Olympics. Hitting harder, grunting louder and moving in closer, he quickly forced a tiebreaker and jumped to celebrate.

Nadal won the final four points to take the tiebreaker and later served out the match.

Ranked 55th, Querrey gave a solid show and became the first player to take a set from Nadal at this Open.

Crowds at Arthur Ashe Stadium love to root for underdogs, especially Americans. The fans in his private box were vocal, particularly the three who had their shirts off and spelled out S-A-M on their chests.

A bit jittery at the start, the 6-foot-6 Querrey boomed 20 aces and showed no fear, trading big shots with Nadal all match long. He drew a standing ovation at the end for his effort, and smiled broadly.

"Came up a little short. The guy's too good," Querrey said.

Nadal next plays unseeded Mardy Fish, who reached the quarterfinals at the U.S. Open for the first time with a 7-5, 6-2, 6-2 win over No. 32 Gael Monfils.

Playing in his ninth U.S. Open and coming off his upset over James Blake, Fish kept busy as his wedding approaches. He will marry "Deal or No Deal" model Stacey Gardner on Sept. 28 — she watched from his private box, minus her shiny No. 2 briefcase.

"I desperately wanted to play well here," he said. "Desperately."

Sixth-seeded Dinara Safina also made it into the quarters, beating Anna-Lena Groenefeld 7-5, 6-0. No. 16 Flavia Pennetta won, defeating No. 32 Amelie Maursemo 6-3, 6-0.

Venus Williams was set to play by day and Serena Williams was ready at night. If they both win, the sisters will next meet in the quarterfinals.

Fish matched the best Grand Slam result of his career, having reached the quarters at the 2007 Australian Open. Ranked as high as No. 17 in 2004, the 26-year-old Fish has worked three years to recover from an injured wrist that required extensive surgery.

Fish waved to his private box after match point. The entourage included his father, Tom, who celebrated his birthday. No such fun for Monfils, who turned 22 Monday.

Safina coasted home after a close first set. She equaled her best result at Flushing Meadows, and kept up the best season of her career.

Safina reached the final at the French Open and later won 15 straight matches before losing the Elena Dementieva in the gold-medal match at the Olympics.