Germany's Thomas Mueller scored the match's only goal, burying a shot in the far post after securing a rebound of a Tim Howard save.
With two wins and a draw, Germany topped the group with seven points, while the U.S. progressed with four. Portugal beat Ghana 2-1 but both were eliminated. Portugal also finished with four points but the U.S. had a better goal difference.
"Obviously it's a huge achievement by our team to come through that group and qualify for the knockout stage," U.S. coach Jurgen Klinsmann said.
After the match, Team USA's Twitter account posted a photo of the team celebrating their advancement to the round of 16:
The Americans will play the Group H winner Belgium on Tuesday in Salvador.
"Once the group is done, another tournament starts," Klinsmann said. "Whoever it is, we'll be prepared."
Mueller scored in the 55th minute with a side-footed shot from the edge of the area as tropical downpours drenched the Arena Pernambuco.
Both teams knew before kickoff that a draw would see them through, but neither held back. The game pitted Germany coach Joachim Loew against his good friend and predecessor Klinsmann, now in charge of the U.S. team.
The two coaches smiled as they shook hands and patted each other on the shoulder after the match.
Germany's goal came after a corner by Mesut Ozil. U.S. goalkeeper Tim Howard did well to punch out a header by Per Mertesacker but the ball fell kindly to Mueller, who pounced on the rebound and rifled a shot inside the far post from the edge of the penalty area. Mueller played despite needing five stitches to close a cut above his right eye sustained in the 2-2 draw with Ghana on Saturday and still visible five days later.
The United States had a chance to level the match in stoppage time, but Alejandro Bedoya's low shot inside the box was swept away by the sliding Mario Goetze, a late substitute. The Americans got a corner but Clint Dempsey's header at the far post went high.
Loew reshuffled his lineup by bringing in forward Lukas Podolski for Goetze and midfielder Sebastian Schweinsteiger for Sami Khedira. Center back Geoff Cameron, whose miscues proved costly against Portugal, was replaced in the U.S. lineup by Omar Gonzalez.
There were many empty seats in the Arena Pernambuco when the match kicked off but fans streamed in during the first half, apparently delayed by traffic jams as torrential rain flooded parts of this northeastern Brazilian city.
Germany was quicker off the mark and Howard intercepted a low cross from Podolski before Michael Bradley made a good clearance and Gonzalez defended well to deny Mueller a shot from close range. Howard's 103th cap was a record for a U.S. goalkeeper and he did well to stop Ozil's shot in the 35th minute.
Graham Zusi had the first good shot for the U.S. but his effort in the 22nd went high.
Referee Ravshan Irmatov of Uzbekistan collided accidentally with Jermaine Jones in the 28th and the American midfielder went down hard but got up. The referee shrugged off the challenge.
Miroslav Klose came on for Podolski at the start of the second half but failed to score and grab sole possession of the World Cup scoring record that he now shares with Brazil's Ronaldo at 15.
Ozil beat Gonzalez to a cross at the start of the second half but sent his header high, while Klose connected with a cross from Schweinsteiger but was off balance and did not get off a clean header.
Aside from an early missed clearance attempt by Gonzalez in the third minute when he flubbed Jerome Boateng's cross and nearly put it in his own net, the move paid off for Klinsmann and the Americans.
They have defied expectations by getting out of one of this tournament's toughest groups. The U.S. is headed to the knockout round in consecutive World Cups for the first time.
A top defender in Major League Soccer, Gonzalez hung tough against high-scoring Germany on a soggy field and with a slippery ball.
Gonzalez hurt his left knee May 3 against Colorado, keeping him out for the start of Klinsmann's structured training camp last month at Stanford, California.
He hoped it wouldn't put him behind. Clearly, Klinsmann trusted Gonzalez to take over a big responsibility on a new-look back line that has been scrutinized from the start for its youth and inexperience on soccer's biggest stage.
Against second-ranked Germany, Gonzalez didn't flinch. His 6-foot-5, 210-pound frame certainly helped him to win possession on headers.
He received a quick, congratulatory pat on the backside from goalkeeper Tim Howard when he cleared a ball in the 14th minute, then a high-five from fellow center back Matt Besler after another hard tackle against Thomas Mueller.
Gonzalez, who joined the national team player pool in 2009, cleared another potential chance for Germany after the ball deflected off Howard in front of the box.
The 25-year-old defender from Dallas made his World Cup debut in the 91st minute of Sunday night's 2-2 draw with Portugal in Manaus, then made an even bigger impact in his first start with his team's World Cup hopes on the line and chants of "U-S-A!" ringing through Arena Pernambuco.
While the Americans didn't exactly get their ideal result, the defense didn't allow the Germans a game like their 4-0 romp over Portugal in the opener.
When the final whistle blew and the Americans quickly learned of Portugal's win, No. 3 goalkeeper Nick Rimando sprinted out and leapt into Gonzalez's arms.
Gonzalez joined his teammates for a walk around the stadium, then stopped and gave a two thumbs-up salute, a wave and a clap before making his exit.
President Obama applauded Team USA hours after it advanced to the knockout round.
"I have to begin by congratulating our U.S. soccer team, Team USA," the president said in his opening remarks at a town hall event in Minneapolis. He joined in briefly as the crowd at Minnehaha Park erupted in chants of "U-S-A! U-S-A!"
Thousands of eager Americans set work aside on Thursday - with or without their bosses' OK - to watch the U.S. men's soccer team play Germany in a key World Cup match.
Fans flocked to official watch parties in places like Chicago's Grant Park, Washington's Dupont Circle and Boston's City Hall Plaza. Many more took part in supervisor-approved, morale-boosting breaks at the office.
The National Trust for Historic Preservation hosted a party for its staff of about 100 with a TV and food.
In Washington, the German Embassy hosted a World Cup watch party at Dupont Circle. Two giant TV screens, security and permits cost about $30,000, and the embassy picked up the tab, CBS DC reported.
Ronnie McCoullough showed up at a midtown Manhattan sports bar at 7 a.m., CBS New York reported.
"I said, 'don't call me in, I'm going to be in the city watching the game,'" he told CBS 2′s Weijia Jiang. "He said I was nuts, then just shook his head at me."
Even New York Mayor Bill de Blasio's office took time out Thursday to cheer on the U.S. men's soccer team.