After all the hand-wringing and all the worry, Chris Kreider ended up staying.

The Rangers signed the 28-year-old winger to a seven-year, $45.5 million contract extension Monday, carrying an annual salary-cap hit of $6.5 million. It was a compromise between the two parties, which seemed unlikely to come together as recently as Sunday night — Kreider had wanted $7 million per, the Rangers wanted six years.

It kept Kreider from reaching the trade market, where he would have been the No. 1 commodity before Monday’s 3 p.m. deadline, and from reaching free agency after the season. So now the Blueshirts have the player they took in the first round (No. 19 overall) in 2009 locked up until he’s 36.

“To have him here was important to us,” general manager Jeff Gorton said. “There’s always doubt with a negotiation and the deadline coming right behind it. We were talking for a long time here in the last couple weeks and thankfully we were able to get a deal.

“But for sure, we had to talk to some teams and go through some scenarios. If this doesn’t happen, are we ready for that? It was obviously the possibility that he might have to be traded.”

There were many interested parties, including the Avalanche, Bruins, Hurricanes and even the Islanders. The Rangers were concerned about how to fit him under the cap, having added just under $20 million in annual salary for the next six years with the offseason signings of Artemi Panarin and Jacob Trouba.

But it wasn’t until after Kreider was signed that the club traded Brady Skjei to the Hurricanes and cleared his $5.25 million per for the next four years off the books. So this was a decision that was based on how much they like Kreider, who missed Monday’s practice due to illness but might be playing the best hockey of his career over the past two months. He has 24 goals and 45 points in 60 games.

“It’s obvious on the ice, and off the ice, what he brings to our team,” Gorton said. “When you look at what he’s doing, his emergence, we feel like he’s still getting better.”

Kreider has hit his stride playing next to Mika Zibanejad, who has become the team’s long-term solution as a top-line center. The two have found an indelible chemistry, and if Kreider left, there was concern on how it would affect Zibanejad’s overall game.

Now, that’s not a worry.

“The fact that [Kreider’s] size, his skating, his scoring ability, the combination he has with Mika, his power-play ability — you add it all up, it’s a player that we’ve had in the organization for a long time, we’ve watched the strides he’s been making,” Gorton said. “And now, when you weigh all the options — having him leave versus keeping him — it became more evident that we wanted to keep him.”

Another big factor was the maturity Kreider brings off the ice, leading by example for the youngest roster in the league. He has taken many neophyte players under his wing in the summers to go train up in Stamford, Conn., and the way he works out and takes care of himself during the season is a testament to his value to the Rangers.

“I wouldn’t say ‘freak of nature,’ but he’s a very well conditioned individual,” team president John Davidson said. “We’re young and young and getting younger, and you need people to lead the way.”