Most of the time in sports, the winners are happy, the losers are sad, and a tie leaves everyone feeling weird and conflicted. The knockout stage of soccer’s Champions League—in which teams play each other twice, home and away—is different. That’s because of the away goals tiebreaker, the most fantastic, arbitrary rule in the beautiful game.

Here’s how it works. At the end of a two-leg playoff—in the Champions League, these playoffs are contested in the round of 16, quarterfinals, and semifinals—the team that has scored the most goals across both games makes it through to the next stage of the tournament. So far, so obvious. But what if, after two games, the teams have scored the same amount of goals? They could go into extra time at the end of that second game. But that extra period gets skipped entirely if one of the two teams has scored more of its goals in its opponent’s stadium.

That’s what happened on Tuesday, in the second leg of the playoff between Roma and Shakhtar Donetsk. Their first game, played in Ukraine in February, ended with the home side, Shakhtar, winning 2–1.

That meant Roma needed to do one of three things to advance to the quarterfinals: 1) outscore Shakhtar by two or more goals, 2) beat Shakhtar 2–1—leaving the clubs tied on aggregate (3–3) and away goals (1–1)—and then win in extra time (or on penalties, if it came down to it), (3) beat Shakhtar 1–0, leaving the clubs tied on aggregate (2–2) but Roma ahead on away goals (1–0).

The game was tied 0–0 into the second half, a score line that meant Roma was losing on aggregate. And then, in the 52nd minute, Edin Džeko caught up with a deep pass and slotted the ball through the keeper’s legs.

Džeko’s goal meant there was no need for overtime. Thanks to the away goals rule, Roma walked away the victor.

Although it might be a bit unfair, determining a winner this way makes for a thrilling possibility: a team going from losing to winning by scoring just one goal. Such a thing usually isn’t possible in soccer, or any sport where you only score one “point” at a time. But in the Champions League, that logic goes out the window, and it’s spectacular when it does.

In 2015, Chelsea and Paris Saint-Germain had played to a 1–1 draw on PSG’s home turf. But in the second leg, PSG erased Chelsea’s lead twice to snatch a 2–2 draw. The last goal came despite the fact that Paris was playing with one man down. A late-game corner kick found its way to captain Thiago Silva, who headed the ball over the goalkeeper for PSG’s crucial second away goal—one more than Chelsea had scored in that 1–1 opener.

It was payback for PSG. The previous year, when the teams also met in the Champions League, Chelsea lost 3–1 in the first game in Paris. In the second leg, at home, minutes before the final whistle, Chelsea’s Demba Ba latched on to a loose ball and poked it into the roof of the net to make the game 2–0. That made the aggregate score 3-3. While all of Paris’ goals were at home, one of Chelsea’s was away, making Chelsea the victor.

But the best example of all may have come in 2009, when an away goal lifted Barcelona from the cusp of defeat into the Champions League final.

After a scoreless draw in the first leg, Barca found itself down 1–0 to Chelsea in London. (It’s always Chelsea, isn’t it?) In the 93rd minute of the decisive second match, the ball ended up at Lionel Messi’s feet. Messi darted the ball to Andrés Iniesta, who crushed it without a shred of a running start.

Barcelona was losing. And then losing. And then still losing. And then they won. Thanks to just one goal. Barcelona would go on to win the Champions League final that year, too, and two more trophies from other competitions. The guy who made that assist, Lionel Messi, would have a lot to do with it.

The away goals rule isn’t a sacred cow. Arsenal manager Arsène Wenger has railed against it for years, including after it played a part in his team’s elimination in 2015. But UEFA (the group that organizes the Champions League) has used the rule since 1965. That year, a quarterfinal had been decided with a coin flip.

Is the aggregate goal system fairer than a round of heads or tails? Definitely. Is it the fairest system possible? Probably not. Sure, goals are tougher to score in a rival’s stadium, after a day’s travel and under the hostile chants of home fans. Still, you can feel for Chelsea, given that they didn’t lose either of their games to Barcelona in 2009 but still came out losers.

Yet what the aggregate goal system might lack in fairness, it makes up for in last-gasp, transformational goals—a comeback collapsed into a single moment of brilliance.