The team made two other moves Wednesday, adding former Saints center Jonathan Goodwin and linebacker Blake Costanzo.
Rogers spent the past six seasons in Washington and had 43 tackles and two interceptions in 2010. The ninth player taken overall in the 2005 draft, the 30-year-old Rogers is likely to replace Nate Clements, who was released by the 49ers in a cost-cutting move last week.
Williams played for Minnesota the past three seasons but was largely a disappointment with the Vikings after joining the team following a four-year stay in Cincinnati. Williams, who was due to make $5.4 million this season, made 50 tackles with one interception last season.
Goodwin's signing shores up a position that had been in flux for the 49ers since David Baas signed with the New York Giants. The 6-foot-3, 320-pounder started 45 games over the past three seasons in New Orleans.