MIAMI — Puerto Rico ousted the favored Dominican Republic from the World Baseball Classic on Wednesday night with a 5-2 victory in front of a raucous crowd of 36,025 at sold-out LoanDepot Park. But the celebratory mood proved short-lived.

While Puerto Rico advanced to the quarterfinals, they likely continue in the tournament without Edwin Díaz, the All-Star closer for the New York Mets, who appeared to suffer an injury to his right leg while celebrating after converting the save, leaving players in noticeable shock in the wake of what should have been a thrilling victory.

In a battle between two Latin American powerhouses, the team with the signature dyed-blonde hair prevailed, escaping the group-of-death Pool D and setting up a quarterfinal showdown Saturday night against Mexico, the winner of Pool C. After Puerto Rico and the Dominican Republic lost to Pool D winner Venezuela earlier, a game that already had enormous emotional implications took on even greater meaning as a win-or-go-home affair.

With vuvuzelas tooting and flags flying and one man holstering a plantain in the waistband of his jeans, an homage to the plátano power that led the D.R. to the 2013 championship in a matchup between the teams, Puerto Rico exacted revenge. Gone, on the strength of a four-run third-inning burst from Puerto Rico, was a Dominican Republic team whose lineup included Juan Soto, Julio Rodríguez, Manny Machado and Rafael Devers, along with a bullpen of devastating arms that made them the favorites to win the fifth edition of the tournament.

No matter to Puerto Rico. Led by manager Yadier Molina, the 10-time All-Star who in the last WBC in 2017 caught for the team that lost in the finals to the United States, Puerto Rico rode five consecutive hits to start the third and never looked back.

Christian Vazquez led off with a home run off D.R. starter Johnny Cueto. Vimael Machin slapped a single to left, Martin Maldonado dropped a bunt single, Francisco Lindor drove in Machin with a single to left and Enrique Hernández plated Maldonado with a Baltimore chop single over Machado’s head. An RBI groundout from MJ Melendez staked Puerto Rico a 4-0 advantage.

Soto cut into it with a titanic shot to start the bottom of the third off Jovani Moran, launching a 92 mph fastball 448 feel to dead center. Puerto Rico answered when Lindor singled up the middle in the fifth and Rodríguez misplayed the ball, which dribbled to the wall and allowed Lindor to book around the bases and extend the lead to 5-1.

The bottom of the fifth presented what wound up as the D.R.’s final opportunity. Against Alexis Díaz, they loaded the bases with a pair of walks and a single. With no outs and the bases loaded, Machado stepped in. One swing later, he grounded into a double play. Though a run scored, Díaz escaped the rest of the inning without harm, and Puerto Rico’s bullpen held firm until the ninth inning.

When the bullpen door swung open, out came Alexis’ brother, Edwin, the best closer in baseball — accompanied by “Narco,” the entrance music that typically accompanies him at Citi Field. Díaz proceeded to strike out Ketel Marte, Jean Segura and Teoscar Hernández.

Diaz was soon swarmed by teammates after the final out; the group was jumping together in the infield when Díaz collapsed to the ground near the pitcher’s mound, and he immediately reach for his right knee.

Díaz was in tears and did not put any weight on his right leg as a coach and trainer helped him limp toward the dugout. He was then placed on a wheelchair in foul territory, his right knee extended. He saluted the fans as he was wheeled off the field and was set to undergo imaging.

Díaz’s brother, Alexis, was also crying as Edwin was wheeled away. Lindor, his teammate on the Mets, stood nearby with his hands on his head.

The 28-year-old right-hander is a two-time All-Star and two-time reliever of the year. He converted 32 saves for the Mets last season with a 1.31 ERA and 118 strikeouts in 62 innings.

ESPN’s Alden Gonzalez and The Associated Press contributed to this report.