Teoscar Hernández homered and drove in three, including the go-ahead run in the seventh inning, and the visiting Los Angeles Dodgers beat the Washington Nationals 6-5 on Wednesday to avoid a three-game sweep.

The Dodgers’ Shohei Ohtani went 2 for 4 with a walk and scored two runs.

The Dodgers, who went 2-4 on their trip to Philadelphia and Washington, snapped the Nationals’ four-game winning streak.

Los Angeles rallied against Eduardo Salazar (0-1) in the seventh. Andy Pages homered to tie it at 5, and Ohtani followed with a single. Tommy Edman walked and Hernández floated a single to right field that scored Ohtani.

The Nationals scored three runs in the first on two hits, including CJ Abrams’ leadoff home run, and two more against Landon Knack in the third.

Washington starter Jake Irvin yielded a single, a walk, a triple and Hernández’s fifth homer of the year to open the game, then didn’t permit another runner to reach third.

Padres 2, Athletics 1 >> Randy Vásquez gave up one hit over five innings and Xander Bogaerts had three hits and scored both of visiting San Diego’s runs.

Bogaerts scored in the third on Gavin Sheets’ sacrifice fly and in the fifth on Oscar Gonzalez’s single.

Yankees 4, Tigers 3 >> Max Fried threw seven shutout innings to outduel high school teammate Jack Flaherty, Ben Rice hit a two-run homer in the seventh and Aaron Judge had a two-run single in the ninth as New York won at Detroit.

The Tigers, trailing 4-0, loaded the bases against Devin Williams with two outs in the ninth, scored one run on a wild pitch and chased the righty on Zach McKinstry’s two-run single. Mark Leiter Jr. entered and retired Justyn-Henry Malloy on a game-ending fly.

New York stopped a three-game losing streak and snapped Detroit’s five-game winning streak.

Fried (1-1) gave up five hits and had 11 strikeouts.

Flaherty, who attended Harvard-Westlake High School in Los Angeles with Fried, struck out nine and gave up three hits and three walks in 5 1/3 innings.

Marlins 5, Mets 0 >> Max Meyer carried a no-hitter into the sixth inning and Miami salvaged the finale of a three-game road series by snapping New York’s six-game winning streak.

Matt Mervis homered and finished with three RBIs for the Marlins.

Meyer (1-1) gave up a leadoff single to Pete Alonso in the seventh and exited after retiring Brandon Nimmo. Meyer walked two and struck out four.

Rangers 6, Cubs 2 >> Corey Seager homered twice as Texas avoided a sweep in Chicago.

Diamondbacks 9, Orioles 0 >> Corbin Carroll homered for the second straight game, Pavin Smith added a two-run shot and Arizona blanked visiting Baltimore.

Mariners 7, Astros 6 >> Randy Arozarena hit a grand slam in the eighth and drew the game-winning, bases-loaded walk in the ninth as Seattle rallied for seven runs over the final two innings to edge Houston.

pirates 2, Cardinals 1 (13) >> Joey Bart singled in the winning run with the bases loaded in the bottom of the 13th to give Pittsburgh a win over St. Louis, despite six hitless innings from Erick Fedde.