A few booming serves later, the Americans were headed for the quarterfinals.
Querrey beat Alves 4-6, 6-3, 6-4, 7-6 (3) to give the U.S. a dramatic 3-2 victory over Brazil, stepping up after teammate John Isner lost to Thomaz Bellucci to send the countries to the deciding fifth match.
"I was very happy with the way I battled through (the match)," Querrey said. "I fought through the tough points and got breaks in the second, third and fourth sets. I was just happy to get through it."
Also advancing Sunday to the quarterfinals were: Canada (over Spain), Italy (over Croatia), Kazakhstan (over Austria) and the Czech Republic (over Switzerland). Clinching spots on Saturday were: France (over Israel), Serbia (over Belgium) and Argentina (over Germany).
The U.S. will host Serbia in the next round in Boise, Idaho, from April 5-7. The other three matchups for the quarterfinals are France-Argentina, Canada-Italy and Czech Republic-Kazakhstan.
Canada is in the Davis Cup quarterfinals for the first time. It defeated a five-time champion Spanish team that was missing Rafael Nadal, David Ferrer and Nicolas Almagro because of injuries and fatigue.
It was the first time since 2000 that a U.S. team needed to win the fifth match to advance, and the 25-year-old Querrey started fast, breaking Alves in the second game. But Alves, ranked No. 141, responded with breaks of his own in the third and ninth games to take the opening set.
Querrey responded with a consistent array of cross-court winners to control play the rest of the way.
While Isner, the highest-ranked singles player in the tie at No. 16, bemoaned his play, Querrey expressed satisfaction with a straight-set win over Bellucci on Friday and the four-setter against Alves on Sunday.
U.S. team captain Jim Courier had special praise for the 20th-ranked Querrey.
"Sam faced some adversity at the end and played a great tiebreaker to get past not closing it out on serve," Courier said. "Those are learning moments for a player, things you can draw on later on in your career. Today is a good day for Sam and our team in a lot of ways."
Querrey was especially effective with his serve. He finished with 26 aces, compared to one for Alves, often clocking 120 mph or faster. When Alves was able to return a serve, it often was with little pace, enabling Querrey to eventually hit winners.
"I fight for all the match, all the match," the 30-year-old Alves said. "My ranking is 145, something like this. I play two guys under 20 in the world. I think I play great tennis here."
Isner got off to a fast start in the first match of the day, then went on to a 2-6, 6-4, 6-7 (7), 6-4, 6-3 loss to the 25th-ranked Bellucci.
The left-handed Brazilian overcame Isner's powerful serve with a strong display of groundstrokes that kept the 6-foot-9 American off balance. He played his best tennis in the second part of the match, breaking Isner in the 10th game of the fourth set and then the eighth game of the fifth set.
A dejected Isner said he needed to improve both his mental frame and his play on the court.
"This hurts a lot. I could have won this match," he said. "I just couldn't quite win the big points. It's almost like I wanted it too badly. Confidence-wise, I'm not even close to where I want to be.
"You can't sugarcoat it with me. My five-set record is atrocious, it's simple as that. It falls on me."
The United States now has nearly three months to get ready for Serbia, which features the world's No. 1 ranked player in Novak Djokovic. Courier said the U.S. team welcomes the challenge of taking on the talented Serbs.
"We wanted to face Serbia. They're one of the great Davis Cup nations right now," Courier said. "If you want to lift this trophy, you need to beat the best teams and that certainly is one of them. We look forward to the challenge."
Kazakhstan 3, Austria 1
ASTANA, Kazakhstan -- Kazakhstan pulled off an unexpected victory over Austria on Sunday to advance to the quarterfinals of the Davis Cup.
Andrey Golubev beat Jurgen Melzer 4-6, 6-3, 6-4, 6-2 in the reverse singles of the World Group first-round tie for Kazakhstan to take an insurmountable 3-1 lead, resulting in the entire team breaking into an on-court celebration dance. The last reverse singles will not be played.
In Saturday's doubles match, Alexander Peya and Julian Knowle kept Austria's hopes by winning a tightly fought contest against Golubev and Yuriy Schukin. Kazakhstan next plays the defending champion Czech Republic away in April.
Czech Republic 3, Switzerland 1
Back on court after both played in an epic 7-hour, 1-minute doubles match on Saturday, Czech No. 1 Berdych beat Swiss team leader Wawrinka 6-3, 6-4, 3-6, 7-6 (5) in the first of the reverse singles rubbers.
Sunday's match took 3 hours, 15 minutes -- lasting less than half the time of the longest match in Davis Cup history.
Wawrinka extended his run of hard-luck losses in 2013, which began against Australian Open champion Novak Djokovic when he lost 12-10 in the fifth set after 5 hours, 2 minutes.
Canada 3, Spain 1
VANCOUVER, British Columbia -- Canada upset a short-handed Spain team Sunday to reach the quarterfinals of the Davis Cup for the first time.
Canada next will play Italy in April.
Raonic and Frank Dancevic won their opening singles matches Friday to give Canada a 2-0 lead before Spain won the doubles Saturday.
France 5, Israel 0
Llodra had helped France win Saturday's doubles and had little trouble beating Noam Okun 6-3, 7-6 (5), before Gasquet followed up his win in Friday's opening singles with a comfortable 6-4, 6-3 win against Amir Weintraub.
Argentina 5, Germany 0
BUENOS AIRES, Argentina -- Argentina completed a 5-0 sweep of Germany on Sunday in their first-round Davis Cup series.
The Argentines reached the quarterfinals on Saturday for the 12th straight time, taking an insurmountable 3-0 lead with a victory in doubles.
Sunday's meaningless reverse singles matches were shortened to three-setters, with Juan Monaco defeating Tobias Kamke 6-4, 7-6 (2), and Carlos Berlocq winning 6-2, 6-4 against Christopher Kas. Argentina will face France in April in Buenos Aires in the quarterfinals.
Serbia 3, Belgium 2
CHARLEROI, Belgium -- Serbia lost both reverse singles matches to Belgium on Sunday after it qualified for the Davis Cup quarterfinals a day earlier.
The two losses left Serbia with a 3-2 victory. It will face the United States next.
Italy 3, Croatia 2
TURIN, Italy -- Fabio Fognini beat Ivan Dodig in four sets in the decisive singles match on Sunday to give Italy a 3-2 win over Croatia in the Davis Cup and send his country to the quarterfinals for the first time in 15 years.
Fognini recovered from losing the first set, which had five breaks of serve, to win 4-6, 6-4, 6-4, 6-4 in 2 hours, 43 minutes.
Dodig racked up 17 aces, but still found himself outplayed by the 44th-ranked Fognini.
Italy will be playing in its first quarterfinal since 1998.
Information from The Associated Press was used in this report.