SAN DIEGO — Nights like these, when the weekend arrives and the Dodgers are in town, don’t often feel like a home-field advantage for the Padres. So many Dodgers fans make the 125-mile drive south that Petco Park is often called “Dodger Stadium South” when the two teams match up.

But that wasn’t the case Friday and Saturday. Petco Park, which had waited 16 years to host fans for a postseason game, was stuffed with locals who rooted hard for the Padres and filled the ballpark with “Beat L.A.” chants that at times felt deafening. And when Josh Hader recorded the final out, capping a thrilling 5-3 victory in Game 4 of the National League Division Series, the place erupted in joy.

The Padres — the same Padres who have spent almost their entire existence chasing the decorated franchise to the north — are advancing to their first NL Championship Series since 1998. They will face the upstart Philadelphia Phillies and hold home-field advantage for the first time in these playoffs. The Padres went on the road to beat the 101-win New York Mets in the wild-card round last weekend then won three straight games against a 111-win Dodgers team that had dominated them over the previous six months.

“It took a team effort to beat a really good team,” Padres third baseman Manny Machado said, “and we did that tonight.”

The Padres held a lead throughout Game 3, but they fell behind early in Game 4. When the seventh inning came around, they trailed 3-0 and faced the grim prospect of returning to Los Angeles to go against Dodgers ace Julio Urias in a winner-take-all Game 5.

Then the Padres staged their biggest rally of the year.

Jurickson Profar, Trent Grisham and Austin Nola — representing a bottom of the order that has come through all month — all reached base to start the inning against the Dodgers bullpen. Ha-Seong Kim, the every-day shortstop in place of the suspended Fernando Tatis Jr., doubled down the left-field line, making it a one-run game. Juan Soto, the big midseason acquisition, lined a base hit to the right side to tie the score. And Jake Cronenworth, who has established himself as a cornerstone player, lined a two-out, two-run single up the middle against lefty reliever Alex Vesia, giving the Padres a two-run lead they would not relinquish.

The Padres, an 89-win team that entered the postseason as the No. 5 seed, became the fifth team to win multiple series in a single postseason against opponents that accumulated 10 or more wins than they did during the regular season. The Dodgers were especially dominant against them. Los Angeles won its last nine regular-season games against San Diego in 2021 and then took 14 of 19 during the regular season in 2022, scoring more than twice as many runs in head-to-head matchups.

The Dodgers’ loss marked the first time a team lost a playoff series to a division opponent after not losing a series to that team during the regular season, according to the Elias Sports Bureau. This series also marked the second time in postseason history that a team eliminated another after winning 22 fewer games during the regular season, last done during the 1906 World Series.

The Padres closed as a +190 underdog at Caesars Sportsbook to win the series, making this the second-biggest betting upset in a playoff series over the past 10 seasons. (The Washington Nationals were +195 to beat the Houston Astros in the 2019 World Series.)

“There’s a lot of good players over here,” Soto said. “I’m happy to be part of this, and I think we have everything we need to reach our goal.”

The Dodgers spent this entire season thinking the same. They set a franchise record in wins and notched a plus-334 run differential that was tied for the fourth largest in history, but they once again came up short. The Dodgers have won the NL West nine times in the past 10 years — the only year they didn’t win it saw them capture 106 wins and fall a game shy of the title — but have come away with only one World Series championship during that stretch, at the end of the pandemic-shortened 2020 season.

Dodgers manager Dave Roberts, a former Padres player and coach, called this latest defeat “crushing.”

“Each guy gave everything they had all year long and a tremendous season,” Roberts said. “The great thing about baseball is the unpredictability, and the tough thing about it is the same thing. Things could have gone either way today to impact the result of the game. It didn’t. We got beat in a series. Nothing I can say is going to make it feel any better. Obviously, we didn’t expect to be in this position.”

The Padres held grand expectations entering the 2021 campaign but fell off in dramatic fashion down the stretch. The ensuing offseason brought a new manager in Bob Melvin, one of the most revered in the sport, and the thought that this franchise might finally take off.

The Padres navigated through most of the ensuing season as an enigma, often following dominant stretches with poor ones. Their hyperaggressive general manager, A.J. Preller, traded for Soto and lights-out closer Hader before the trade deadline, but those moves were followed by the stunning revelation that Tatis, the face of their franchise, had tested positive for a performance-enhancing substance. The Padres persevered, doing just enough to secure a spot in Major League Baseball’s expanded postseason field. And when the playoffs began, they suddenly played their sharpest baseball of the season. Their fans naturally rallied behind them.

“The crowd was unbelievable,” said Joe Musgrove, the local product and lifelong Padres fan who pitched six innings of two-run ball in Game 4. “It was everything I could have imagined.”