LOS ANGELES (AP) — Gavin Lux allowed a routine two-out grounder to roll between his legs in the second inning, and the Philadelphia Phillies jumped through that opening to score four unearned runs.

With the Dodgers down to their final out three hours later, Lux got an improbable opportunity for redemption — and he crushed it.

Lux atoned for his fielding mistake with a two-run double in the ninth inning, and Los Angeles avoided a four-game series sweep with a 5-4 victory on Sunday.

“Probably shouldn’t even have been in that situation anyway, so I kind of had to make up for earlier,” Lux said after his first career walk-off RBI.

The Phillies led 4-0 after Lux's error, and they were up 4-2 after Aaron Nola threw seven gutsy innings of four-hit ball. Lux drew a leadoff walk in the eighth and scored on Mookie Betts’ double off Jeurys Familia, but the reliever escaped with two groundouts.

Philadelphia then got within one strike of its first four-game sweep at Dodger Stadium since 1985, but couldn't close it out.

The bases were empty when Cody Bellinger abruptly delivered a two-strike, two-out triple off closer Corey Knebel (0-3). Ten pitches later, it was over.

After Chris Taylor walked, Lux drove home both runners with a drive to the right field corner. He set off a frenzied celebration at Chavez Ravine for a big crowd that included actor Tom Hanks, who put both hands to his head in disbelief.

Betts also homered for the Dodgers, who avoided their first five-game skid since April 2019. Los Angeles hadn’t won in walk-off fashion since last July 20.

“I'm sure (the error) was on Gavin's mind all day long,” Dodgers manager Dave Roberts said. “I don't want to say it's the biggest win of the year with a short sample, but it's a big one. Guys are feeling real good right now.”

Although the Phillies' perpetually problematic bullpen failed again, the powerhouse Dodgers have done it to better teams. They hadn't done it lately, though: The Dodgers had lost five of six and were staring at another disheartening defeat to an opponent that was significantly better than them all weekend.

“You can't always be in front," Bellinger said. “It's nice to get hit with some adversity and see how we respond, because it's not always going to be smooth sailing.”

Shane Greene (1-0) pitched two scoreless relief innings in his season debut for Los Angeles.

Rhys Hoskins had a two-run single during only the Phillies' second loss on a seven-game West Coast road trip, snapping a four-game winning streak. Garrett Stubbs had two hits and drove in a run, but the Phillies couldn't get back above .500 for the first time since April 12.

After battering the Dodgers for 29 runs and 37 hits in the first three games, the Phillies played the finale without Bryce Harper. The NL MVP underwent treatment on the torn ligament in his elbow after going 8 for 12 with three homers and eight RBIs in the first three games.

Nola struck out eight and walked two while pitching out of a handful of jams. He was the second straight Phillies starter to last seven innings against the Dodgers, who had only let two other opposing starters survive that long all season.

FIRST-TIMER

Michael Grove yielded four hits and three walks while pitching into the fourth inning in his major league debut. Grove got promoted from Double-A Tulsa to help Los Angeles’ depleted rotation, which is missing several potential starters due to various medical problems.

“I thought it's as good as we could have expected,” Roberts said. “It was a good learning experience for him.”

BAD SWING

Philadelphia’s Odúbel Herrera swung and missed at a low slider that went through his legs in the seventh inning while facing Yency Almonte.

TRAINER'S ROOM

Phillies: C J.T. Realmuto got a day off to rest.

Dodgers: Clayton Kershaw played catch for the first time since going on the injured list Friday with inflammation in a pelvic joint. He is expected to have a bullpen session Wednesday. ... Andrew Heaney will travel with the team next week and likely will throw in the bullpen. He has been out for a month with left shoulder pain.

UP NEXT

Phillies: After a day off, Philadelphia opens a three-game home series with San Diego on Tuesday. The Phillies haven't named a starter.

Dodgers: Tony Gonsolin (3-0, 1.33 ERA) takes the mound in Chavez Ravine on Monday for the first of four games in three days against the Arizona Diamondbacks, who counter with Madison Bumgarner (2-1, 1.78).

___

More AP MLB: https://apnews.com/hub/MLB and https://twitter.com/AP_Sports