New York led 4-0 before Derek Jeter's three-run double broke the contest open in the top of the ninth.
Earlier, Alex Rodriguez and Hideki Matsui hit RBI doubles in the fourth and Johnny Damon slammed a two-run homer in the seventh.
Damon, Jeter and Chad Moeller all had two hits.
Pettitte (3-1) did not walk a batter, struck out five and 59 of his 89 pitches were strikes.
Three relievers mopped up for the Yankees, who stopped a three-game losing streak.
Baltimore's run scored on Brian Roberts' eighth inning sacrifice fly.
Jay Payton had two of the seven hits for the Orioles, whose bid for a three-game home sweep of the Yankees since 2005 failed.
Losing pitcher Steve Trachsel (1-3) surrendered three earned runs and seven hits in 6 1/3 innings with three walks and five strikeouts.