Some hits do not help the batting average, but they can win games.

The Dodgers were locked in a 4-4 tie with the Kansas City Royals on Wednesday night when A.J. Ellis came to the plate with the bases loaded in the eighth inning. Normally this is an oddly difficult situation for the Dodgers, who are the worst-hitting team in the majors (seven for 47, .149) with the bases loaded.

Royals reliever Wade Davis delivered an unexpected answer to the Dodgers’ bases-loaded problem, hitting Ellis in the left biceps with a pitch to force in what would be the winning run.

The Dodgers tipped their caps, and left Kauffman Stadium with the 5-4 victory that completed a six-game road trip with four wins.

With Kenley Jansen having pitched in four of their last five games, Manager Don Mattingly went to Brian Wilson in the ninth.

Wilson pitched a scoreless final inning, picking up his first save of the season and first since April 12, 2012, but not without getting saved himself by Scott Van Slyke.

The Royals had a runner on second with one out when Lorenzo Cain lined a shot to right field. Anyway, it looked as if it was going into right. But the 6-foot-5 Van Slyke jumped straight up and  snared the ball, beginning a rather remarkable game-ending double play.

Dan Haren started for the Dodgers and continued his now lengthy run of mediocrity.

Haren started the season 3-0 with a 2.03 earned-run average in his first five starts. In 11 games since, he owns a 4.68 ERA.

And he continues to be hurt by giving up the home run. The soft-throwing Haren gave up two more homers Wednesday, both solo shots. Haren has given up 18 home runs on the season, tied for the second-most  in the majors.

Cain opened the bottom of the first with a home run, only his third of the season. Matt Kemp got the run back with a solo homer of his own in the second.

The Dodgers took the lead in the third after one-out, back-to-back triples by Dee Gordon (one of his four hits) and Yasiel Puig. For Gordon, it was his ninth triple of the season, tops in the majors. An Adrian Gonzalez fly to left was deep enough to sacrifice Puig in for the second run.

Mike Moustakas’ RBI single in the fourth pulled the Royals back to within one, but the Dodgers went up by two in the fifth when Gordon singled, stole second and scored on a Puig double.

But Kansas City scored two more in the bottom of the inning to tie the score, 4-4. On his 10th pitch, Jarrod Tyson led off the inning with his first home run of the season. Cain singled with one out and stole second before Haren walked Eric Hosmer.

That ended the night for Haren. Jamey Wright took over, but a wild pitch advanced both runners. Billy Butler hit one up the middle, but shortstop Miguel Rojas made his latest outstanding play, fielding the ball and throwing to first for the out.

Cain scored, but with Rojas stopping the ball from getting through, he forced Hosmer to stop at third and prevented a second run from scoring. Wright struck out Alex Gordon for the third out.

Haren was charged with four runs on five hits and two walks, with three strikeouts in his 4 1/3 innings.

Kansas City starter James Shields recovered from his rocky start to go seven innings, allowing four runs on seven hits and two walks.

The Dodgers’ winning “rally” in the eighth came after Gonzalez and Andre Ethier singled, and Van Slyke drew a walk. That preceded Ellis' taking one for the team.