ANAHEIM, Calif. -- For 19 innings, and six hours and 31 minutes, the Los Angeles Angels and Boston Red Sox played the longest game ever in Angel Stadium history.

They began playing Saturday night and ended Sunday morning.

In fact, the game was so long, even when Albert Pujols led off the 19th inning with what was believed to be the game-winning homer, the game wasn't officially over.

The ball barely cleared the fence in right-center field, so Red Sox manager John Farrell asked for a replay challenge to find out if a fan reached below the yellow line and committed interference.

After a short review, the home run stood, and the Angels could celebrate a 5-4 victory.

Pujols hit his 16th career walk-off homer, his first as an Angel. It came off Brandon Workman (1-6), a starting pitcher who was facing his first batter of the game.

"In that situation, I'm just trying to start the inning with a base hit and get a chance to get in scoring position to score the game-winning run," Pujols said. "I got a good pitch to hit.

"It tells you something about this ballclub. The way we've been playing the last five ballgames, you could say, 'Screw it, let's come tomorrow and try to get a win.' A game like this could turn things around, the way we won. If it does, it's worth it to play 19."

Starter-turned-reliever Matt Shoemaker (10-4) threw three scoreless, hitless innings to get the win and end the Angels' four-game losing streak.

For the last-place Red Sox, it was just another tough loss.

"As hard-fought as we played this game, as did they, sometimes these extended games when you come out on the short end can feel like two losses," Farrell said. "But I couldn't be more happy and proud of the way we continued to battle through all 19 innings tonight."

It was a game that had a little bit of everything, maybe too much of everything. Each team used nine pitchers.

Red Sox second baseman Dustin Pedroia stole two bases on one pitch, a key play that led to a run in the 14th inning and put the Red Sox in position to win before the Angels rallied in the bottom of the inning.

Pedroia was on first base with one out and designated hitter David Ortiz at the plate. The Angels had the shift on for Ortiz, with third baseman Pujols playing on the right side of the infield.

Shortstop Erick Aybar was the only Angels defender on the left side of the infield when Pedroia broke on a pitch to Ortiz. Pedroia stole second base in a close play, then noticed that nobody was covering third.

Pedroia took off for third and easily beat pitcher Cory Rasmus in a race to the bag.

Ortiz followed with a sacrifice fly to left field, scoring Pedroia with the go-ahead run.

"We knew about it, they were prepped, unfortunately stuff happens you don't react like maybe you should," Angels manager Mike Scioscia said of Pedroia's double steal, saying it was Rasmus' responsibility to cover third on the play. "And it was a heads-up play by Dustin Pedroia."

The Angels rallied in the bottom of the 14th inning, loading the bases with no outs and designated hitter Mike Trout in position to be the hero.

Instead, Trout grounded into a fielder's choice, driving in catcher Chris Iannetta from third with the tying run. The Angels had the potential winning run on third with one out and Pujols up, but Pujols couldn't get the run home, grounding out to third.

Red Sox reliever Junichi Tazawa, who came in the game to start the inning, struck out center fielder Josh Hamilton to escape.

The game lasted so long that Angels starter Garrett Richards' no-hit bid was long forgotten. Richards took a no-hitter into the seventh inning.

The Red Sox, though, scored three in the seventh -- two of the runs unearned thanks to two errors -- turning a 2-0 deficit into a 3-2 lead.

The Angels tied the game in the eighth inning on a solo homer by Trout, his 26th of the season.

Richards was coming off his first career shutout in his previous start against the Los Angeles Dodgers.