When a team in need of a spark gets one, it usually comes in the form of a key home run or a walk-off win or a dominant pitching performance.

The Texas Rangers needed a spark Sunday afternoon. Heck, they needed a win.

They got both, though somewhat improbably, but no one was arguing with the result.

A sacrifice fly by Elvis Andrus that traveled no more than 20 feet off the infield dirt and a blooper from Alex Rios that fell in front of one of the best center fielders in the game helped lift the Rangers to a 4-3 victory at Angel Stadium.

The win allowed the Rangers to avoid a three-game sweep to the Los Angeles Angels and remain 1 1/2 games behind Oakland in the American League West. Nick Tepesch and six relievers limited the Angels to their lowest output of the series, though Tanner Scheppers made sure of that in the eighth.

“It was huge,” Andrus said. “You’ve got to find a way to win games, and sometimes it’s going to be with bloopers. If that’s the way we’re going to win games, I’ll be really happy with it.”

Rios drove in two runs from the No. 3 spot in the lineup, his first game there since being acquired Aug. 9, including the game-winner and the game’s first run on a homer to left-center field.

But the Rangers were down 3-2 with one out in the seventh when Leonys Martin walked and Ian Kinsler followed with a ground-rule double ahead of Andrus.

The Angels elected to play the infield in to keep the tying run from scoring on a grounder, but Andrus lifted a pop-up into shallow right-center field.

Second baseman Grant Green had no shot at the ball, and right fielder Kole Calhoun raced in for a diving catch. But he was on the ground long enough for Martin to tag up and score for a 3-3 tie.

“If the infield is back, the second baseman catches it in his back pocket,” said Kinsler, who was at second and also tagged on the play. “The infield was in. It was a good spot to hit it.”

Rios followed with a blooper toward Mike Trout in center field. But the ace defensive player dived and couldn’t make the catch as Kinsler coasted home with the go-ahead run.

“He’s got that good reputation,” Rios said of Trout. “I guess I hit it in the right spot.”

Rios homered three batters into the game for the Rangers, who struck in the first inning for the second consecutive game only to see the lead disappear after having a chance to build on it.

Tepesch, making his first start since July 6, worked a scoreless first inning, but Calhoun started the second with a liner into the right-field seats to tie the game. Tepesch pitched around a two-out double in a scoreless third and was lifted at 63 pitches in the fourth after a one-out single by Mark Trumbo.

Joseph Ortiz promptly allowed a double to Hank Conger, but Trumbo was cut down on a rundown on Grant Green’s grounder to third. Andrew Romine, though, doubled down the left-field line to score both runners for a 3-1 lead.

Martin and Andrus were responsible for the second Rangers run in the fifth. Martin singled off Jason Vargas to start the inning and went to second as Kinsler grounded out. Andrus followed with a liner to center that brought in Martin.

Down 3-2, Ortiz and Alexi Ogando (6-4) combined on a scoreless sixth. After the Rangers jumped ahead in the seventh, Jason Frasor, Neal Cotts, Scheppers and Joe Nathan combined on three scoreless innings to end it.

Scheppers, though, had to work in the eighth after Cotts allowed a leadoff double to Calhoun. He went to third as Trumbo grounded out to second base, but Scheppers struck out Conger and got Green on a liner to center.

Said Scheppers, who prefers to pitch to contact rather than go for strikeouts: “I normally never would look for the strikeout. I’m looking for a weak ground ball where he can’t get extended.”

His work, along with a pop-up-turned-sacrifice-fly and a bloop double were enough to send the Rangers home for their biggest homestand of the season on a high note. They will host Pittsburgh for three games beginning Monday and then welcome first-place Oakland over the weekend.

They needed a win Sunday.

“We needed it bad,” Washington said. “It’s only one win, but it was huge.”