Each player would have become a restricted free agent if not signed by July 5.
Desjardins, 26, had two goals and an assist in 42 games with the Sharks in 2012-13. He also had 61 penalty minutes, 53 hits and won 54.2 percent of his faceoffs. He had a plus-1 rating and 28 hits in 11 Stanley Cup Playoff games.
"Andrew is a player that plays with an edge, can kill penalties and has the ability to play the north/south game we desire," Sharks general manager Doug Wilson said. "He always competes hard as is always there for his teammates."
In 135 NHL games spread across parts of three seasons, Desjardins has seven goals, 16 assists and 112 penalty minutes.
Sheppard, 25, returned to the NHL with the Sharks in 2012-13 after missing most of the previous two seasons with a career-threatening leg injury. In 32 games this season, he had one goal, three assists, 12 penalty minutes and 63 hits, and he averaged 10:28 of ice time in 11 playoff games. He was voted the team's nominee for the Bill Masterton Memorial Trophy by the San Jose chapter of the Professional Hockey Writers' Association.
"James played his best hockey for us in the playoffs and his game continues to improve after missing the past couple seasons," Wilson said. "He's got good size and strength and we think he can elevate his game to an even higher level."
Chosen by the Minnesota Wild with the ninth pick of the 2006 NHL Draft, Sheppard has 12 goals and 41 assists in 256 games with the Wild and Sharks.