ANAHEIM — The Arizona Diamondbacks snapped a three-game losing streak and avoided getting swept by the Los Angeles Angels with a 5-1 victory on Sunday.

Merrill Kelly grinded through five innings that were effective enough, while the D-backs took advantage of a key defensive miscue from L.A. to put up a crooked number on an otherwise scoring-deficient ballgame.

The D-backs wrapped up the road trip 3-4 and enter the All-Star break 47-50.

“At the end of the day, I think we’re all frustrated by what’s happened the past couple days,” manager Torey Lovullo said. “I think they blocked out all the noise, all the things that can possibly be a distraction on the last day of the first half, and they won a baseball game. I saw the reaction in the dugout. That’s the stuff we’re looking for. It was a good game.”

Kelly tied a season high with four walks, as he threw at least 21 pitches in each of the first four innings.

A double play and three strikeouts allowed him to avoid any damage in the first two innings, although the Angels took a 1-0 lead in the third. Zach Neto led off with a walk, tagged up and took second on a fly ball to Alek Thomas and scored on a Mike Trout single to left.

From there, Kelly retired the next seven batters with three strikeouts to end his outing with five innings (98 pitches), one earned run, one hit, four walks and six strikeouts.

“An adventure,” Kelly described his outing. “Just a lot of walks, a lot of balls, a lot of non advantageous counts. They did a good job of controlling the zone, making me throw pitches in the zone, which I just didn’t do a good job of today. Luckily I was able to walk away with only one hit, one run.”

Kelly finished the “first half” with a 3.34 ERA and 1.05 WHIP in 116 innings. He threw 12 innings with two earned runs over his last two appearances.

“Obviously, if I could take that New York game out of there, it would feel a lot better,” Kelly said when asked about his first half. “Overall, happy with how I feel. I’m glad I started feeling better there towards the end.”

When asked whether he expected to be named an All-Star replacement at some point, Kelly said he didn’t, feeling he had not pitched well enough in June to position himself for that honor.

The difference in the game was four unearned runs from the Diamondbacks against Angels starter Jose Soriano in the fourth inning. Angels third baseman Yoan Moncada missed a potential double play ground ball with two on and nobody out, as the Eugenio Suarez chopper brought home the tying run.

With two outs, Blaze Alexander lined a go-ahead double to left field, and Jose Herrera hit a check-swing double down the left-field line to bring home two more.

Suarez doubled home the fifth run in the fifth inning to take a 5-1 lead, which was the score when Kelly exited.

The Diamondbacks’ bullpen (John Curtiss, Kevin Ginkel and Kendall Graveman) provided four shutout innings, stranding four runners in the final three frames.

Ketel Marte out of lineup

The Diamondbacks started Alexander at second base with Marte receiving a day to rest and recover. Lovullo said pregame that Marte is not at 100% after dealing with right groin discomfort.

“He could play today if needed, so he’ll be available off the bench,” Lovullo said. “I just wanted to give him some rest because the day game after the night game, going hard trying to recover from that discomfort in the groin.”

Eugenio Suarez appreciates Home Run Derby support

Suarez hit his 30th and 31st home runs of the season on Saturday, and after the game, his manager and teammates stuck up for him being snubbed from the Home Run Derby.

Suarez has said he’d be excited to participate if asked, which never happened, but he did not want to ask to compete.

“ I’m happy for the support they’ve been expressed for me,” Suarez said. “It’s something out of my control. I just do my thing on the field for my teammates … Just happy to be part of the All-Star Game.”

Up next for the Diamondbacks

The Diamondbacks are sending three All-Stars to the Midsummer Classic in Atlanta: Suarez, Corbin Carroll and Marte.

The club will host a voluntary workout on Thursday before the “second half” begins on Friday at Chase Field. The D-backs will host the St. Louis Cardinals (50-46) for three games to start a six-game homestand.