SAN DIEGO — The New York Yankees drafted Gerrit Cole out of high school in June 2008 but lost him to UCLA. They tried to trade for him in January 2018 but lost him to the Houston Astros. They faced him in Game 3 of the American League Championship Series eight weeks ago and lost again.

It took the largest contract for a pitcher in baseball history, but finally, at the height of a wild, fast-moving free agent market, the Yankees got their man. In a throwback to the days when the Yankees ruled the winter with their aggressive moves and bottomless bankroll, they agreed to terms with Cole, 29, late Tuesday night on a nine-year, $324 million contract.

The deal surpassed Stephen Strasburg’s seven-year, $245 million deal with the Washington Nationals, agreed to just a day earlier, as the largest for a pitcher in the sport’s history, and trails only Bryce Harper’s 13-year, $330 million deal with the Philadelphia Phillies, signed in February, as the largest for any free agent. Mike Trout’s 12-year, $426.5 million extension with the Los Angeles Angels, signed in March, remains the largest contract of any type in baseball history.

The Yankees beat out a handful of other suitors, most notably the Angels and Los Angeles Dodgers, for the services of Cole, the AL Cy Young runner-up for the Astros in 2019, when he went 20-5 with a 2.50 ERA and 326 strikeouts. He was even better in October, going 4-1 with a 1.72 ERA and 47 strikeouts in 36⅔ innings, helping the Astros to the AL pennant.

In a span of about 32 hours during baseball’s annual winter meetings, agent Scott Boras got Strasburg — who opted out of his Nationals contract shortly after being named World Series MVP — and Cole signed to deals totaling more than half a billion dollars, in what already has been one of the most active and lucrative free agent markets in recent years.

And Boras still has third baseman Anthony Rendon, who is in the market for a deal in the neighborhood of Strasburg’s, as well as left-handed pitcher Hyun-Jin Ryu, who is now left, along with lefty Madison Bumgarner, as one of the most desirable starting pitchers on the market.

The Yankees, whose pennant drought stretches back to 2009, made Cole their top free agent target and made a concerted and aggressive push to get him signed. Last week, General Manager Brian Cashman, Manager Aaron Boone and former Yankees and Astros pitcher Andy Pettitte led a contingent of Yankees brass who traveled to Southern California to meet with Cole.

Though the Yankees also met with Strasburg, they made little secret of the fact they preferred Cole, who is two years younger and has none of the injury baggage.

Cole moves to the top of a 2020 Yankees rotation that should include right-handers Luis Severino and Masahiro Tanaka and lefties James Paxton and J.A. Happ. Tanaka, in January 2014, was the last free agent whom the Yankees signed to a nine-figure deal.

Having not only bolstered their own rotation but diminished that of the Astros, their biggest rivals for AL supremacy, the Yankees must be regarded as the favorites in their league. They have made four trips to the ALCS (2010, 2012, 2017, 2019) since their 2009 World Series title but have not made it back to the World Series.

The contrast between last winter’s free agent market and this one is stark and unmistakable. A year ago, Boras and his fellow agents struggled to build a market for their high-end clients, with both Harper and Manny Machado waiting until late February, long after spring training camps had opened, to sign their deals with the Phillies and San Diego Padres, respectively.

But this winter — following a postseason dominated by two teams, the Nationals and Astros, constructed around starting pitching — demand was higher across the board, and the marketplace, at least for high-end starters, moved with uncommon speed, resulting in the megadeals for Strasburg and Cole.

For a change, the Yankees acted like the Yankees of old again this winter and free agency acted like the free agency of old. The Yankees got the best pitcher on the market, perhaps the best pitcher on the planet, and are again the most feared team in the American League.

Read more on baseball: