Wayne Rooney helped lift D.C. United to an Open Cup win over Philadelphia on Tuesday. (Jonathan Newton / The Washington Post)

After almost two hours of scoreless soccer, with a U.S. Open Cup clash between D.C. United and the Philadelphia Union deep into rainy extra time, the match finally erupted with a flurry of goals — and eventually Wayne Rooney’s game-winning penalty kick in the final minute of extra time.

The players with tired legs and wet jerseys battled late into the evening at Audi Field before United won, 2-1, advancing to the round of 16 over a shorthanded Union squad.

All three of the game’s goals came in the final seven minutes of extra time, beginning with Anthony Fontana’s score for Philadelphia in the 113th minute of play. D.C. responded, with Chris McCann’s header off Rooney’s corner in the 118th minute. Then, after Luciano Acosta drew a foul in the penalty box, Rooney blasted the ball into the net soon after to keep the game from extending further into penalty kicks.

“It showed a little bit of moxie to come back,” United Coach Ben Olsen said. “That’s an easy one to fold on. You never want to go to extra time and deal with the penalty kicks.”

Last year, Orlando City eliminated United from the Open Cup on penalty kicks, and D.C. had gone to penalty kicks in three of its past six first-round Open Cup games.

“It was kind of a stalemate,” United defender Steven Birnbaum said. “It ended up opening up in both of the extra time halves. After they scored, we kind of just threw numbers forward.”

United played without a few regular contributors, causing this game to become a test of depth, but still wasn’t pressed for players to the extent of Philadelphia, which made it to the Open Cup final last year.

The Open Cup, a knockout tournament in American soccer, features both professional and amateur teams, but MLS clubs do not enter until the fourth round, when 32 squads remain. United’s Wednesday matchup was just one of the five fourth-round games that pitted two MLS teams against each other. United has won the tournament three times, most recently in 2013.

Frequently in this tournament that takes place during the MLS season, clubs might opt to hold out regular starters with their league slate in mind. But with the MLS in a dark period of its schedule, United played most of its usual starters. Olsen said he never considered taking Rooney out of the game, and Rooney said he hopes to be involved going forward in the tournament, too.

“It’s a chance for us to win a trophy, so I want to play, whether it’s a USL or MLS team,” Rooney said. “It’s important that we keep a good feel about the place and we try to win the game and go even further in the competition.”

Joseph Mora returned to the lineup and played more than 90 minutes, subbing off during extra time, in his first game back since he broke his jaw against Orlando City on March 31. He only came off to ensure “we didn’t go backwards with him,” Olsen said. McCann took his place and eventually headed in the tying goal.

Gold Cup call-ups have depleted the rosters of both D.C. and Philadelphia. For the next few weeks, United will be without American winger Paul Arriola (Concacaf Gold Cup) and Venezuelan midfielder Junior Moreno (Copa America).

Chris Durkin recently represented the U.S. at United States at the Under-20 World Cup in Poland, but the 19-year-old midfielder already has returned to D.C. after the American squad lost Saturday in the quarterfinals. Durkin still couldn’t play in Wednesday’s game because of a red card in United’s loss to Orlando City in last year’s Open Cup. Russell Canouse, a regular starter at defensive midfield, also missed the game with a minor injury.

With those absences, Antonio Bustamante, a rookie who hasn’t appeared in an MLS game yet, started at defensive midfield with Leonardo Jara, who’s a regular starter but usually in the right back spot.

“[Jara] won a few duels that really kind of were contagious with our group,” Olsen said. “I thought he was as good as anybody on the night.”

The Union had more significant voids, though, thanks to national team duties, as well as this tournament’s limit of five international players in the game-day squad of 18. Philadelphia called up four academy players from its USL affiliate, the Bethlehem Steel.

Both teams used backup goalkeepers in the matchup. Philadelphia was without Andre Blake, who’s with the Jamaican national team that recently beat the United States in a friendly at Audi Field, while United’s Bill Hamid missed the game for precautionary reasons like Canouse. Chris Seitz, United’s backup goalkeeper, played a mostly mistake-free game, finishing with five saves against a Philadelphia attack that produced 24 shots.

Olsen called United’s start passive. The team took just four shots in the first half with none on goal compared with the Union’s 13 shots with three on goal in the opening 45 minutes of play. But eventually, even if only in the waning moments, United prevailed to move forward in the tournament.

“They just had a better mentality from the get-go, and then we got into the game, and it became important to us,” Olsen said. “But it took a little bit.”

Read more on soccer:

Women’s World Cup results, schedule and standings

Alex Morgan is the face of U.S. soccer and now its golden boot

Did USWNT players celebrate their goals with too much gusto? World Cup rout sparks debate.

Should women’s soccer players be paid as much as men? Trump: ‘We’ll talk about that later.’