The victory gave the United States nine points in Group F. The newly promoted Germans have three points and their hopes of advancing could depend on winless Belarus, which has yet to play Slovakia and Germany. Canada also has nine points and plays the Czech Republic on Saturday.
"It doesn't matter that I got the goals," said Stastny. "If they can help the team win, and I think it did, we'll take it."
In Moscow, Julien Sprunger scored a pair of goals to help Switzerland close in on a spot in the quarter-finals with a 4-1 win over Denmark in Group E.
The United States has scored 21 goals in five games, while the Germans have one of the best defences at the tournament.
"We were expecting (the Germans) would play well. The Czechs beat us and they beat the Czechs," Stastny said.
United States goalie John Grahame made 23 saves for the shutout, while Erik Cole assisted in all three goals.