In exchange for Smith, the 49ers get an undisclosed 2013 draft choice, and a conditional pick in the 2014 NFL Draft from Kansas City, the team said on the first official day of the new National Football League calendar.
Smith, the number one overall pick of the 2005 draft by San Francisco, had been the long-time starter for the Niners before losing his job to Colin Kaepernick, who shined after filling in when Smith suffered a concussion midway through last season.
Kaepernick helped the Niners reach the Super Bowl, where they narrowly fell to the Baltimore Ravens 34-31.
Once the 49ers had decided to go with Kaepernick, it seemed only a matter of time before San Francisco found a new home for Smith, who had established himself as a starter.
"We would like to thank Alex for his contributions to the 49ers organization over the past eight years," 49ers General Manager Trent Baalke said in a statement.
"He is a true professional who represented the 49ers with class on and off the field."
Smith was 6-2-1 as a starter in the 2012 campaign, throwing 17 touchdowns and just five interceptions one season after he steered the Niners to the NFC title game where they lost in overtime to the eventual Super Bowl champion New York Giants.
San Francisco acquired receiver Boldin from Baltimore for an undisclosed draft choice.
Last season, Boldin started 15 games and led the Ravens with 65 receptions for 921 yards and four touchdowns. He also added 22 catches for 380 yards and four touchdowns in the postseason. (Reporting by Larry Fine in New York; Editing by Frank Pingue)