The Champions League final seems immune to upsets. Real Madrid won three of the last five finals, with Bayern Munich and Barcelona taking the other two. And now Madrid is one win away from its fourth title in six years and third in a row. But this list of winners should not obscure that smaller clubs have come close. Atletico Madrid has taken Real Madrid to extra time twice in the last five finals, and Borussia Dortmund lost a nail-biter of a final 2-1 to Bayern. This year, it is Liverpool that has a real shot at upending a traditional power structure in the Champions League. And according to FiveThirtyEight’s Soccer Power Index, a Liverpool victory would not even be that much of an upset: SPI gives the team a 47 percent chance of lifting the trophy on Saturday.

How did Liverpool become a true Champions League contender? To a certain degree, this is unsurprising. For starters, Liverpool is no upstart, at least historically. The club has five European Cups and its revenues are among the highest in European soccer. But the Reds have played in the Champions League only four times in the last decade, and this season is the first time they have even reached the knockout stages since 2009. It took an extensive and highly successful rebuilding effort to get Liverpool to the cusp of a European trophy. The three key components of this effort were smart analytics, innovative tactics and the usual helping of good luck.

Liverpool struck gold in the transfer market

The engine of this Liverpool team is its front line. Manager Jurgen Klopp prefers a 4-3-3 formation with four defenders, three central midfielders, and a forward line with a central striker flanked by two wide attackers. Center forward Roberto Firmino and left forward Sadio Mane combined for 44 goals and 22 assists between the Premier League and the Champions League, while Mohamed Salah matched that production almost by himself with 42 goals and 14 assists.

Every one of these players was acquired in the transfer market: Firmino in 2015, Mane in 2016 and Salah last summer. Hitting on star attackers in three consecutive transfers is a major accomplishment no matter what your budget, but it’s especially impressive for Liverpool, which cannot afford to pay as much as the world’s richest clubs — as was made evident when Philippe Coutinho forced his way out of Liverpool for Barcelona in January. To build one of the world’s most dangerous front lines, Liverpool had to look for relative bargains, which more or less ruled out peak-age players at the height of their powers. Further, with Klopp’s pressing style, the team had to avoid the typical lumbering center forward and look for players versatile enough to press high and interchange in the attack. They needed attackers who could play anywhere in the front line. To find these key pieces, the team turned to analytics.

One of the simplest ways to identify undervalued attackers is with expected goals (xG) and expected assists (xA) — two metrics that estimate the quality of scoring chances, built from information collected by sports-data company Opta. The ability to get on the end of good scoring chances, or to create them with a telling pass, is more stable across seasons than the ability to finish off such a chance. Over the last three years, very few young players have put up big numbers in xG and xA per 90 minutes while playing on smaller clubs and getting the majority of their minutes from outside the center forward role. Liverpool found three of them.

The Egyptian-born Salah was coming off a 15-goal campaign with Roma in Serie A, but the signs of even bigger breakout were there. Liverpool inked him for around $47 million in June of last year, which was then a club record, and 42 goals later, that deal is looking like an incredible bargain. Firmino and Mane both similarly showed their potential before their Liverpool signings: Firmino’s production for Hoffenheim in 2014-15 and Mane’s for Southampton in 2015-16 were among the best player seasons in the sample I examined, which included non-striker attacking players in the five biggest leagues over the previous three seasons. Liverpool used data to identify players who weren’t just on a hot streak but who demonstrated repeatable skills, and those purchases have paid off in goals.

Liverpool adjusted to improve its defense

Jurgen Klopp has called his style of play “heavy metal” soccer. His teams focus on creating and exploiting transition opportunities, the moments when neither team has established possession or set its defensive structure. His teams press high up the pitch, closing down opponents even when they have the ball well into their defensive half. In Klopp’s first season with Liverpool in 2015-16, his team led the league with a roughly 52 percent success rate in breaking up new opposition possessions. This metric calculates how often and how successfully a team closes down its opposition early in the opponent’s possession, which reflects the degree to which they implement a pressing defensive style. The next season, with a year of training under their belt, Klopp’s players stepped up their pressure, breaking up nearly 54 percent of opposition possessions early. Once again, this rate led the league. However, there were some drawbacks to this style: In both those first two seasons, Liverpool was relatively vulnerable to direct attacks. If the first line of press failed, the Reds often found themselves chasing back to stop a counterattack headed for their goal. This is measured by direct attacks into the final third of the pitch, which shows when an opposition team can break forward into dangerous areas.

This season, Klopp has drilled his team to drop the pressing intensity in matches where it’s not needed. While they still can press high, Liverpool can also sit back and absorb pressure, as they did to great effect in the Champions League quarterfinal against Manchester City. This improved tactical flexibility has yielded results — reducing opponents’ goals, chances and successful fast attacking moves by a significant margin.

Klopp has improved Liverpool’s defense this season How Liverpool has fared in three defensive statistics during seasons under manager Jurgen Klopp Seasons with Klopp Defensive stat 2015-16 2016-17 2017-18 Direct attacks to final third conceded per match 25.0 21.2 18.7 Pressing rate 51.7 53.7 49.5 Expected goals conceded per match 1.03 0.97 0.86 2015-16 only includes games when Klopp was manager. Source: Opta Sports

Liverpool got lucky too

It is practically impossible to win a cup final without some good fortune. Liverpool, by using its resources smartly and developing more flexible tactics, put itself in position to take advantage of good fortune when it arrived. And this year, every time the UEFA drew teams into competitive fixtures, Liverpool benefited.

Liverpool had the luck of the draw in this tournament Change in each team’s chance of winning the Champions League before and after the draws, according the Soccer Power Index, 2018 Team Change in chance of winning Liverpool +11 Bayern +9 Barcelona +6 Sevilla +3 Man City +2 Juventus -2 Roma -3 Real Madrid -11 Source: FiveThirtyEight’s Soccer Power Index

In the round of 16, Liverpool got to face Porto and avoid a match against Real Madrid or Juventus. This increased the Reds’ chance of winning the Champions League from about three percent to about five percent. For the quarterfinals, Liverpool got a tough matchup in Manchester City, but most of the other remaining teams were also extremely strong, so the draw caused only marginal movement in Liverpool’s chances of winning the Champions League. Then the semifinal draw brought the greatest bounty, as the Reds avoided Bayern Munich and Real Madrid to face Roma instead. This increased Liverpool’s chance of winning the league from about 20 percent to 29 percent.

The table to the left shows the net total improvement, in percentage points, of the chance SPI gave each team of winning the Champions League before and after the draw for each round. Among the teams that reached the quarterfinals, none benefited more than Liverpool. (And this calculation doesn’t even include Liverpool’s luck in the group draw, when the Reds were given the weakest of the eight groups.)

Liverpool can win

As the table of team luck shows, Real Madrid has reached the Champions League final by facing a true gantlet. They got Paris Saint-Germain in the round of 16, Juventus in the quarters and Bayern Munich in the semifinals. However, the draw is not the only method by which good fortune may affect the outcome. Real would not have made the finals if Bayern Munich had not been extremely profligate with its chances. Bayern scored only three goals, but based on the chances the team got, we would expect them to have gotten 6.9 goals.

But the way Bayern got all those chances bodes well for Liverpool. They pressed high and created turnovers. If Liverpool can execute its pressing game as effectively as Bayern did, the Reds should also be able to make trouble for Real Madrid. In this game, Liverpool’s defensive flexibility probably will be less help — sitting back and allowing Cristiano Ronaldo time to find space in the penalty area does not seem like the best option. With heavy metal soccer, Klopp may finally win a Champions League and bring a trophy back to Liverpool.

CORRECTION (May 24, 2018, 6:15 p.m.): A previous version of this article incorrectly described Real Madrid’s path to the Champions League finals this year. They played Bayern Munich in the semifinals.