The Patriots waived Marsh on Tuesday after acquiring him in September from the Seattle Seahawks in exchange for fifth- and seventh-round draft picks.
Marsh (6 foot 4, 245 pounds) appeared in 46 games in his four NFL seasons. Three of his four career sacks came in 2016 while with the Seahawks. He was Seattle's fourth-round pick in 2014 after recording 13 of his 15 career sacks at UCLA in his final two seasons.
Marsh is the second defensive player the 49ers have claimed off waivers this week. The club acquired former Jacksonville Jaguars defensive lineman Sheldon Day on Monday. The 49ers released defensive linemen Tony McDaniel and Datone Jones within the past week.
The 49ers are at their roster maximum of 53 players. The club will have to clear a roster spot if Tank Carradine, as expected, is activated off injured reserve in order to play Sunday against the Seattle Seahawks at Levi's Stadium.