With quite a few open spots on the Rangers’ back end, they didn’t want to let Brendan Smith hit the open market and lose him to the highest bidder.

The Blueshirts agreed to terms Wednesday with the rugged 28-year-old defenseman on a four-year, $17.4 million deal, carrying an annual salary-cap hit of $4.35 million. The deal also carries some no-trade coverage, according to Smith’s agent, Anton Thun.

Smith came over from the Red Wings at the 2017 trade deadline in exchange for a third-round pick. As a lefty, he showed an ability to play the right side — which the Rangers desperately need. He also showed a physical edge and snarl in his game that was lacking on the roster.

The right side of the Rangers blue line still is in question after the club bought out the remaining three years on Dan Girardi’s contract. Smith and Nick Holden — two lefties — are the returning players on the right side. Veteran righty Kevin Klein is contemplating retirement, which would take his $2.9 million cap hit off the table. Newly acquired 21-year-old righty Anthony DeAngelo also will compete for a spot. The left side is covered with Ryan McDonagh, Brady Skjei and Marc Staal.

Smith’s signing also likely puts an end to any idea the Rangers would go out and sign coveted free-agent right-handed defenseman Kevin Shattenkirk to the long-term deal he will command on the open market.

It was clear Smith liked his few months on Broadway, helped by the fact Derek Stepan and McDonagh, his college teammates at Wisconsin, were on the team. Stepan since has been traded to the Coyotes, but the affable Smith already seemed embedded in the locker room, saying on breakup day he had “a blast” playing for the Rangers.

“There’s so many different variables, you try to figure out what’s the best for myself and for my family,” Smith said after the Blueshirts lost to the Senators in the second round. “Kind of just go about it like that. It’s tough. It’s my first option to do this, and I’m just going to see how things go.”

This gives general manager Jeff Gorton a little easier handle on the free-agent market, which opens Saturday. Working with about $15 million of salary-cap space — with Klein still on the books — Gorton still has to sign restricted free agents Mika Zibanejad and Jesper Fast, both of whom hold arbitration rights. Gorton made it seem at the draft this past weekend he wants to get Fast’s deal done sooner rather than later. He might wait to see how the market shakes out before signing Zibanejad.

Surely Gorton will try to upgrade in talent, especially at center. He also needs to sign a veteran backup goalie, which probably won’t cost much, but will be important.

For now, at least he knows he has Smith, and that’s a start.