BALTIMORE — Aaron Judge hit a tying home run in the eighth inning, Starlin Castro’s RBI single keyed a four-run ninth, and the New York Yankees rallied to defeat the Baltimore Orioles 7-3 on Sunday and avert a three-game sweep.

It was the first loss of the season for the Orioles, who started the day as the majors’ only unbeaten team at 4-0. After pulling off comeback victories in the first two games of the series, Baltimore blew a three-run lead in the finale.

RAYS 7, BLUE JAYS 2: Steven Souza Jr. hit a three-run homer and was involved in a scrum after a slide during Tampa Bay’s win at home.

Both benches briefly emptied in the second when Blue Jays shortstop Troy Tulowitzki took issue with Souza’s slide into second base on Logan Morrison’s double-play grounder. No punches were thrown.

ANGELS 10, MARINERS 9: Albert Pujols hit his 592nd career homer and a tying two-run single in the ninth before Cliff Pennington’s drive to the wall capped the Angels’ rally from a six-run deficit at Anaheim, California.

Pennington’s single drove in Mike Trout to end an unlikely comeback by the Angels, who trailed 8-1 in the eighth and 9-3 in the ninth.

TWINS 4, WHITE SOX 1: Miguel Sano and Jorge Polanco homered to back Ervin Santana’s six scoreless innings as Minnesota won at Chicago. Santana (2-0) held the White Sox to two singles and lowered his ERA to 0.69.

RANGERS 8, ATHLETICS 1: Joey Gallo homered and had a career-high five RBI to back left-hander Martin Perez, and Texas won at home.

ASTROS 5, ROYALS 4: Jake Marisnick hit a tying home run off Kelvin Herrera in the ninth and Evan Gattis drew a bases-loaded walk from Matt Strahm in the 12th, helping host Houston halt a three-game losing streak.

NATIONAL LEAGUE

PIRATES 6, BRAVES 5: Starling Marte hit a two-run homer off Jose Ramirez in the 10th inning, lifting Pittsburgh to a win at home.

The Braves had taken the lead in the top of the 10th on Tyler Flowers’ RBI groundout.

PHILLIES 4, NATIONALS 3: Cesar Hernandez hit an RBI single with two outs in the ninth to lift Philadelphia at home.

Pinch-hitter Ryan Zimmerman had delivered a tying, three-run homer with two outs in the top of the ninth for Washington.

CUBS 7, BREWERS 4: Kyle Schwarber and Ben Zobrist hit home runs, Jake Arrieta threw seven strong innings and Chicago took 2 of 3 at Milwaukee.

REDS 8, CARDINALS 0: Scott Feldman allowed four hits and struck out six in six innings, and Cincinnati took 2 of 3 at St. Louis. Adam Duvall had three hits, including a home run, and two RBI for the Reds.

DODGERS 10, ROCKIES 6: Corey Seager hit a two-run homer and Los Angeles scored seven two-out runs in avoiding a road sweep.

Justin Turner added a two-run double as the Dodgers won their 98th game at Coors Field – most of any visiting team.

GIANTS 5, PADRES 3: Hunter Pence and Buster Posey hit consecutive homers, and Johnny Cueto struck out seven in seven strong innings as San Francisco snapped a four-game losing streak.

METS 5, MARLINS 2: Noah Syndergaard made a blistering return to the mound, overpowering Miami for much of the night in New York’s win at home.

INTERLEAGUE

DIAMONDBACKS 3, INDIANS 2: Patrick Corbin threw six scoreless innings, Chris Owings homered and had three hits, and Arizona completed a three-game sweep at Phoenix.