Dilfer, who won a Super Bowl with Baltimore in 2001, will give the 49ers depth behind Smith, who struggled as a rookie last season after being the No. 1 overall pick in the 2005 draft.

"Trent was a player we had interest in last season," 49ers coach Mike Nolan said in a statement. "We were looking for a veteran quarterback with experience that could help mentor Alex Smith. Trent fits the bill on both counts and we are excited to have him with the 49ers."

Dilfer signed a four-year deal with the Browns last year after stints with the Ravens and Seattle Seahawks. He went 4-7 as Browns starter before losing the job to rookie Charlie Frye. Dilfer completed 59.8 percent of his passes last season for 2,321 yards, with 11 touchdowns and 12 interceptions.

"Trent Dilfer played an important role in the making over of our football team last year," Browns general manager Phil Savage said in a statement. "At this point, to add Ken Dorsey and to give Trent the opportunity to go back home to California is a win-win for all parties."

Dilfer, who played in college at Fresno State, has started 107 career games, throwing for 106 touchdowns and 117 interceptions. He made the Pro Bowl with Tampa Bay in 1997 after passing for 2,555 yards and 21 touchdowns.

Dorsey started 10 games in his three years in San Francisco, including three last season. He completed 48-of-90 passes for 481 yards, two touchdowns and two interceptions in 2005.

Cody Pickett is San Francisco's third-string quarterback and the team also drafted Michael Robinson in the fourth round last month. Robinson, a quarterback in college at Penn State, is expected to mostly be used as a running back, receiver or kick returner in San Francisco.