The deal was made shortly before Friday's 3 p.m. ET moratorium for the Olympic break.
The 34-year-old Shelley played in 137 games with San Jose, posting three goals, 11 assists and 285 penalty minutes.
Shelley's 1,300 penalty minutes since the start of his first full season in 2001-02 are the second-most in the NHL. Only Ottawa's Chris Neil has more with 1,440.
The Sharks are tied with Washington for the most points in the NHL with 89. The Rangers are tied for 10th in the East with Atlanta heading into Friday's games.