OAKLAND, California — Left-hander Wade Miley threw 6 2/3 shutout innings, and the Boston Red Sox defeated the Oakland A’s 2-0 on Wednesday at O.co Coliseum, handing right-hander Sonny Gray his first loss of the season.

Miley (2-4) allowed just five hits but walked four and repeatedly pitched his way out of jams as he snapped a three-game losing streak and won for the first time since April 21 against Tampa Bay.

Gray (4-1) allowed just one run on three hits over seven innings. He struck out nine and didn’t walk a batter for the first time this season.

The A’s (13-23) fell to 1-11 in day games, the worst record in the major leagues, and 1-10 in series finales. They ended their six-game losing streak Tuesday night with a 9-2 victory against Boston, but they’ve won back-to-back games just once all season. They dropped to 1-6 against left-handed starters.

The Red Sox (16-18) took two out of three from the A’s and won a series of at least three games in Oakland for the first time since July 24-26 in 2006.

Right-handed reliever Junichi Tazawa pitched 1 1/3 scoreless innings, and closer Koji Uehara pitched a scoreless ninth for his seventh save.

First baseman Daniel Nava went 2-for-3 with an RBI and scored a run for the Red Sox. Left fielder Hanley Ramirez had two hits in four at-bats and scored a run.

Shortstop Marcus Semien hit a triple and catcher Josh Phegley a double for the A’s. Left fielder Coco Crisp snapped his career-long 0-for-39 skid with an infield single in the fifth.

The Red Sox grabbed a 1-0 lead in the second inning against Gray. Ramirez grounded a leadoff single to right field and advanced to second on a wild pitch. Nava blooped an RBI single down the left-field line with two outs.

Boston added an unearned run in the eighth inning. Nava lined a leadoff single off right-hander Evan Scribner and moved to second with one out when Scribner hit catcher Sandy Leon with a curveball after getting ahead 1-2 in the count.

With two outs, second baseman Dustin Pedroia reached on an infield single, and Nava raced home when Semien’s throw to first sailed high and wide for an error.

The A’s wasted multiple chances against Miley, going 0-for-13 with runners in scoring position through six innings.

Miley walked the first two batters he faced but retired the next three. He stranded two runners in the second. Then, in the third, Semien hit a leadoff triple, but Miley retired right fielder Josh Reddick, designated hitter Billy Butler and third baseman Brett Lawrie and escaped unscathed.

Late Tuesday night, Stephen Vogt, Josh Reddick and Marcus Semien each homered, powering the A’s to a 9-2 victory over the Red Sox.

Left-hander Drew Pomeranz allowed two runs on four hits over seven innings for the A’s, who snapped their season-high, six-game losing streak. Pomeranz (2-3) ended his three-game skid and won for the first time since his first start of the season on April 10. He struck out three and walked none.

Vogt hit his team-high ninth home run of the season, a two-run shot in the first inning. He scored twice and drove in two runs, giving him an American League leading 30 RBIs for the season. Vogt matched his career high for homers in a season.

Reddick went 4-for-5 with his sixth home run of the season, a solo blast in the third. He drove in three runs, scored twice and raised his batting average to a team-high .346.

Semien hit a solo shot in the fourth, his sixth homer of the season. He also tripled and singled in five at-bats, finishing a double shy of the cycle. Second baseman Eric Sogard went 2-for-4 with a double and three RBIs.

Red Sox right-hander Justin Masterson (2-2) gave up six runs on six hits over 2 1/3 innings, his shortest outing of the season.

NOTES: Masterson, who had his second straight rough start Tuesday night, will miss his start Sunday at Seattle and probably is headed to the disabled list, manager John Farrell said. Masterson had a “full exam and workup” with the team’s medical staff. “There’s not one specific area to the arm or shoulder that is a cause or reason why we’re seeing reduced velocity and reduced action,” Farrell said. “There’s some fatigue that’s involved.”