The Union clinched a berth in the knockout rounds of Major League Soccer’s summer tournament at Disney World with a 2-1 win over Inter Miami late Tuesday night.

Kai Wagner scored in the first half and Kacper Przybylko scored in the second on a brilliant counter-attack, entertaining viewers who stayed up past 12:30 a.m. for the game’s end.

Wagner opened the scoring in the fifth minute after the first of many smart plays in the game by Brenden Aaronson.

Ray Gaddis sprung Aaronson down the right side, and the Medford native cut in along the end line with a deft touch. Aaronson’s pass back toward the middle was deflected by Miami centerback Andrés Reyes toward Jamiro Monteiro, who let the ball bounce to Wagner. He stepped up and launched a grass-cutting drive from 23 yards that Miami goalkeeper Luis Robles could only get a piece of.

Miami star Rodolfo Pizarro tied the game in the 36th minute, using some nifty footwork in the six-yard box to shake off Mark McKenzie and slot the ball past a stranded Andre Blake. The goal was pretty from start to finish, with two one-touch flicks by Inter players in the full-field buildup.

Miami had 57.8% of the possession in the first half, but the shots were just 4-4. The standout statistic was the fouls: 12 by the Union and nine by Miami. Referee Silviu Petrescu blew his whistle early and often, and both teams deserved it.

Union manager Jim Curtin made his first substitution at halftime, withdrawing Sergio Santos for Ilsinho. Santos got tangled up with — and perhaps stepped on — by Reyes in the 29th minute, and though he shook it off Curtin didn’t take any chances.

The second half started as a tactical chess match, as Miami jammed up the Union’s midfield. Suddenly, the Union were the team with more possession and not enough to do with it.

In the 63rd minute, the Union broke the dam. After Martínez stopped a Miami free kick, Ilsinho cleared the ball from the end line, Monteiro jumped over the pass to let Aaronson have it, and the Union were off to the races.

Aaroson flew down the left wing, then played a cross-field pass that Monteiro brilliantly dummied to let Przybylko collect. Przybylko cut in from the right side, continued forward and slotted an inch-perfect shot to the far post.

“That goal is an example of how the Union want to play,” Curtin said, invoking the swashbuckling style of English Premier League champion Liverpool. “It was quick, simple passes, always forward and central.”

Martínez was withdrawn in the 72nd after cramping up so badly that he needed assistance to get off the field to a stretcher. Warren Creavalle replaced him as the midfield’s defensive anchor. Fortunately, Martínez was seated on the Union bench a few minutes later.

Curtin said Martínez and Santos were both fine by the time the game ended.

In the 76th, Union centerback Jakob Glesnes — starting to give Jack Elliott a night off — was whistled for a dubious-looking penalty kick with Miami’s Jerome Kieswetter next to him. If it was a foul, there wasn’t much contact; and if it was a handball, replays showed the ball hit his shoulder more than his arm. The replay booth advised Petrescu to go to the monitor, and he reversed his initial call.

Monteiro’s night ended in the 81st minute, replaced by Anthony Fontana. A minute later, the Union caught another break when Miami’s Roman Torres hit the crossbar with a header off a corner kick. On the ensuing counter-attack, Fontana should have scored but fluffed his chance with Aaronson waiting.

The Union had to survive eight minutes of stoppage time, and they helped themselves with a crafty 92nd-minute corner kick sequence that Ray Gaddis (yes, really) nearly finished. There was a scare at the other end in the 95th, but Blake made a firm save to snuff it out.

Next up for the Union is the group stage finale against Orlando City on Monday (8 p.m., TUDN and Twitter). Orlando beat New York City FC, 3-1, in Tuesday night’s early game to clinch their own berth in the round of 16. Orlando holds first place in the group on goal difference.

Group A standings so far

1. Orlando City: 2-0-0, 6 points, +3 goal difference

2. Union: 2-0-0, 6 points, +2 goal difference

3. Inter Miami: 0-0-2, 0 points, -2 goal difference

4. New York City FC: 0-0-2, 0 points, -3 goal difference