Marsh, a UCLA alum, played in nine games for the Patriots, with one start, and was credited with 14 tackles and one sack.
For San Francisco, Marsh could play a couple of positions, including the Leo defensive end or Sam (strongside) linebacker. The Niners have managed to create a fairly consistent pass rush this season but have struggled to get home for sacks. End Elvis Dumervil leads the team in that category with 4.5, and the Niners are 22nd in the league with 20.
In the Niners' ongoing search for pass rush help, Marsh is the second defensive lineman they have plucked off the waiver wire this week.
On Monday, the Niners claimed defensive tackle Sheldon Day off waivers from Jacksonville to fill an already vacant roster spot. They released defensive end Datone Jones on Tuesday, opening up the spot that Marsh now fills.
The team is also expected to bring defensive end Tank Carradine back from injured reserve this week, a move that would require another corresponding transaction.
Marsh, 25, has 57 tackles and four sacks in 46 career games.
ESPN's Mike Reiss and Nick Wagoner contributed to this report.