Judge tied a career high with six RBIs and recorded his fifth career multi-homer game when he hit fastballs from Mike Wright and Richard Rodriguez in the fourth and sixth innings.
While Judge hit his 10th and 11th homers of the season against the Orioles, others contributed to New York's 10th win in 16 meetings against Baltimore.
Jonathan Schoop, Trey Mancini and Chance Sisco hit solo homers for Baltimore, which lost for the seventh time in eight games since Sept. 5. Joey Rickard added an RBI single and Caleb Joseph hit a run-scoring double in the eighth.
New York's Masahiro Tanaka (12-11) capitalized from the early offense and held the Orioles to two runs on eight hits in seven innings.
Miley (8-13) produced the shortest start of his career, allowing six runs and six hits while getting one out. He threw 19 pitches to seven hitters and lost his third straight start.
The Yankees took a 1-0 lead six pitches into the game on an RBI double to left field by Sanchez. A run-scoring ground out by Matt Holliday and an RBI single by Headley made it 3-0, and the Yankees knocked out Miley when Frazier blasted a 3-1 fastball over the center-field fence for a three-run homer.
Baltimore threatened in the fourth when Schoop opened the inning with his 31st homer, and the Orioles put two on with nobody out after Frazier misplayed a grounder by Trey Mancini for an error. Tanaka struck out Chris Davis and Mark Trumbo before getting Welington Castillo on a groundout.
The Yankees quickly struck back as Judge hit a 2-1 fastball by Wright into the first row of the right-center field bleachers. His three-run blast pushed the lead to 9-1.
NOTES: The Yankees were going to honor former team executive Gene "Stick" Michael with a moment of silence and a video tribute but the sound system was experiencing technical difficulties. Michael, who was the GM of the team in the early 1990s, died last Thursday at 79. ... Baltimore manager Buck Showalter said RHP Ubaldo Jimenez will start Sunday's game as the team gives RHP Dylan Bundy an extra day. ... Manager Joe Girardi said Greg Bird (back spasms) is expected to be in the lineup Friday when the Yankees face a right-handed starting pitcher. Bird entered as a pinch hitter in the seventh for RF Aaron Judge.