Knicks’ Isaiah Hartenstein during the first quarter against the Indiana...

Knicks’ Isaiah Hartenstein during the first quarter against the Indiana Pacers in Game 2 at Madison Square Garden. Credit: Newsday/J. Conrad Williams Jr.

Even when the salary-cap figures made it a long shot, the Knicks maintained hope that they could lure Isaiah Hartenstein back to remain a part of what the franchise is building.

But when the Oklahoma City Thunder raised the stakes with a massive offer, the Knicks had no shot to keep him.

Hartenstein, a key piece of what the Knicks achieved this past season, has decided to depart for a three-year, $87 million deal with the Thunder, according to a league source.

The Knicks were working to clear cap space to be able to fit Hartenstein in at the most they could allow under the collective bargaining agreement with only Early Bird Rights.

The source said the Knicks placed the max offer they could give Hartenstein — a four-year, $72.5 million deal — on the table as soon as the NBA Finals ended. They offered a contract starting at approximately $16 million next season. And that offer remained in place for him as free agency opened Sunday night. But the Thunder offer overwhelmed that possibility, averaging $29 million per season.

After a meeting in Eugene, Oregon, with Thunder officials on Sunday, the two sides came to an agreement on the deal, which had been looming for months as the biggest threat to the Knicks’ chances of retaining Hartenstein.

“NYC thank you for taking my family in and making my time there so special,” Hartenstein posted on his Instagram account on Monday afternoon. “Every time I went out on the court I always gave it my all for the city and I felt the love right back.

“NYC will always have a special place in my heart. All love #foe”

Hartenstein spent two years with the Knicks. He played in all 82 games in his first season, emerged as a starter this past season when Mitchell Robinson underwent ankle surgery and held that starting job after Robinson returned.

Hartenstein averaged a career-best 8.3 rebounds per game and fit well in the starting lineup with his passing ability and work in the pick-and-roll game with Jalen Brunson.

Those skills made him attractive to the Thunder, too. It gives them much-needed rebounding and rim protection along with a complementary piece to their already loaded offensive lineup. His arrival will allow Chet Holmgren to move to power forward and continue to thrive on the perimeter.

There was little doubt that Hartenstein was going to have a well-timed payday. His free agency came in the wake of the best season of his career after a journeyman start in which he floated through four teams in four years before joining the Knicks. Even that came after he spent time in the G League and overseas.

In his time in New York, Hartenstein developed into the premier center available in this free-agent class. He averaged 7.8 points, 8.3 rebounds and 2.5 assists in 75 games, including 49 starts, during the past regular season. He then averaged 8.5 points, 7.8 rebounds and 3.5 assists in 13 playoff games.

“It’s great timing,” he said earlier in the season. “I can’t lie about that. I feel like I always knew I could be a starter in the NBA. Now just proving it with Mitch being out and I know I’m a starter in the NBA.”

Brunson said during the season: “Outside of this organization, there was a question mark on ‘would he be able to do this?’ All of us believed in him inside this organization, the team, the coaching staff, everything we knew he was capable of, and he’s been performing. He’s been playing well.

“He’s been just locked in every single night, doing the dirty work and just playing his style of basketball, which has been fantastic. So we knew he was capable of this.”

The Knicks’ acknowledgment that their offer to Hartenstein was still on the table meant that they had a plan to add to the Mikal Bridges trade with the Nets. Now they must turn their attention to finding a replacement. The possibility of trading Robinson certainly will be off the table, and the market for a low-cost backup is deteriorating quickly.

Andre Drummond signed with the 76ers when free agency opened Sunday. Mason Plumlee, Alex Len and Kevin Love quickly agreed to new deals and Jonas Valanciunas signed a three-year, $30 million deal with the Wizards.

The Knicks have Jericho Sims on the roster as a backup, and after not offering a qualifying offer to Precious Achiuwa, they still can add him back to the roster.

The Knicks had interest in center Goga Bitadze, but he reportedly re-signed with the Magic for three years and $25 million.

SUBSCRIBE

Unlimited Digital AccessOnly 25¢for 6 months

ACT NOWSALE ENDS SOON | CANCEL ANYTIME