The US advanced to the quarterfinals for the second year in a row. It has missed out only twice since 1998, when the 16-team format was started.
O'Sullivan, a late roster addition from the Houston Aeros of the American Hockey League, gave the Americans a 3-2 lead at 2:27 in the last period with Latvia short-handed.
From Mark Cullen's setup pass from the right, O'Sullivan fired a one-timer past Latvia goalie Sergejs Naumovs.
Ryan Suter added an insurance goal eight minutes later on another power-play.
Also scoring for the Americans were Ryan Malone and Dustin Brown, who's the second-best goalscorer in the tournament with four. Brown had a hat trick in the opener against Norway.
For Latvia, Lauris Darzins and captain Aleksandrs Semjonovs scored.
Craig Anderson went the distance for the Americans in goal, making 22 saves.