NEW YORK >> The Los Angeles Dodgers won their second World Series championship in five seasons, overcoming a five-run deficit with the help of three Yankees defensive miscues and rallying on sacrifice flies from Gavin Lux and Mookie Betts in the eighth inning to beat New York 7-6 in Game 5 on Wednesday night.

Aaron Judge and Jazz Chisholm Jr. hit back-to-back home runs in the first inning, Alex Verdugo’s RBI single chased Jack Flaherty in the second and Giancarlo Stanton’s third-inning homer against Ryan Brasier built a 5-0 Yankees lead.

But errors by Judge in center and Anthony Volpe at shortstop, combined with pitcher Gerrit Cole failing to cover first on Betts’ grounder, helped Los Angeles score five unearned runs in the fifth.

After Stanton’s sixth-inning sacrifice fly put the Yankees back ahead 6-5, the Dodgers loaded the bases against loser Tommy Kahnle in the eighth before the sacrifice flies off Luke Weaver.

Winner Blake Treinen escaped a two-on, one-out jam in the bottom half by retiring Stanton on a flyout and striking out Anthony Rizzo.

Walker Buehler, making his first relief appearance since his rookie season in 2018, pitched a perfect ninth for his first major league save.

“We’re obviously resilient, but there’s so much love in the clubhouse that won this game today,” Betts said. “That’s what it was. It was love, it was grit. I mean, it was just a beautiful thing. I’m just proud of us and I’m happy for us.”

When Buehler struck out Verdugo to end the game, the Dodgers poured onto the field to celebrate between the mound and first base, capping a season in which they won 98 games and finished with the best regular-season record.

“There’s just a lot of ways we can win baseball games,” Buehler said. “Obviously the superstars we have on our team and the discipline, it just kind of all adds up.”

Shohei Ohtani, the Dodgers’ record-setting $700 million signing and baseball’s first 50-homer, 50-steal player, went 2 for 19 with no RBIs and had one single after separating his shoulder during a stolen base attempt in Game 2.

Freddie Freeman hit a two-run single to tie the Series record of 12 RBIs, set by Bobby Richardson over seven games in 1960. With the Dodgers one out from losing Friday’s opener, Freeman hit a game-ending grand slam reminiscent of Kirk Gibson’s homer off Oakland’s Dennis Eckersley in 1988’s Game 1 that sparked Los Angeles to the title.

The Dodgers earned their eighth championship and seventh since leaving Brooklyn for Los Angeles — their first in a non-shortened season since 1988. They won a neutral-site World Series against Tampa Bay in 2020 after a 60-game regular season and couldn’t have a parade because of the coronavirus pandemic.

These Dodgers of Ohtani, Freeman & Betts joined the 1955 Duke Snider and Roy Campanella Boys of Summer, the Sandy Koufax and Don Drysdale era that spanned the three titles from 1959-65, the Tommy Lasorda-led groups 1981 and ’88 and the Betts and Clayton Kershaw champions of 2020.

Dave Roberts won his second championship in nine seasons as manager as the Dodgers, matching Lasorda and trailing the four of Walter Alston. The Dodgers won for the fourth time in 12 Series meetings with the Yankees.

New York remained without a title since winning its record 27th in 2009. The Yankees acquired Juan Soto from San Diego in December knowing he would be eligible for free agency after the 2024 Series. The 26-year-old star went 5 for 16 one RBI in the Series heading into intensely followed bidding on the open market.

Judge finished 4 for 18 with three RBIs.

Cole didn’t allow a hit until Kiké Hernández singled leading off the fifth. Judge, who an inning earlier made a leaping catch at the wall to deny Freeman an extra-base hit, dropped Tommy Edman’s fly to center. Shortstop Anthony Volpe then bounced a throw to third on Will Smith’s grounder, allowing the Dodgers to load the bases with no outs.

Cole struck out Lux and Ohtani, and Betts hit a grounder to Rizzo. Cole didn’t cover first, pointing at Rizzo to run to the bag as Betts outraced the first baseman.

Freeman followed with a two-run single and Teoscar Hernández hit a tying two-run double. Max Muncy walked before Kiké Hernández grounded into a forceout on Cole’s 48th pitch of the inning.

Stanton’s sixth-inning sacrifice fly off Brusdar Graterol put the Yankees ahead 6-5, but the Dodgers rallied one last time in the eighth.