Updated

The Rangers have agreed to terms with restricted free-agent defenseman Ryan McDonagh on a six-year, $28.2 million contract.

The new deal announced Monday will carry an annual salary-cap hit of $4.7 million for New York, which is close to the financial ceiling with players still left to re-sign, such as forwards Derek Stepan and Carl Hagelin.

But reaching an agreement with the 24-year-old McDonagh, a cornerstone defenseman, was key. Had he received an offer sheet from another team, the cap-challenged Rangers could have been forced to let him go or make trades to free up space to keep him.

McDonagh had four goals and 15 assists in 46 games last season and ranked second on the team with 78 blocked shots, third in average ice time at over 24 minutes per game, and fourth with a plus-13 rating.