J.A. Happ wanted a three-year deal in free agency but instead settled for coming back to the Yankees for two years at $17 million per season with a vesting option for the third year, and now we know how the left-hander can trigger the option.

According to The Post’s Joel Sherman, Happ will qualify for the $17 million option in 2021 if he throws 165 innings or makes 27 starts in 2020.

While Happ tossed 177 2/3 innings and started 31 games last season split between the Blue Jays and Yankees, he didn’t hit either mark in 2017 (145 1/3 innings and 25 starts) because he missed six weeks due to elbow inflammation.

Happ turned 36 in October, and his return to the Yankees’ rotation was key after fellow southpaw Patrick Corbin went to the Nationals. Happ will slide in along Luis Severino, Masahiro Tanaka, CC Sabathia and another lefty, newly acquired James Paxton.

The Yankees also could add another starter in a trade, and they are interested in 27-year-old Japanese free-agent lefty Yusei Kikuchi.

In Happ, the Yankees bring back a reliable pitcher who went 7-0 with a 2.69 ERA in 11 starts following the July trade from Toronto in exchange for Brandon Drury and Billy McKinney. Happ, though, flopped in his lone postseason outing with the Yankees, when he allowed five runs in just two innings in a Game 3 loss to the Red Sox at Fenway Park in the ALDS.