The deal is worth $40 million, including $22 million guaranteed, sources said.
Smith, who has played his entire four-year career with theBaltimore Ravens, follows WR Anquan Boldinto San Francisco. Baltimore traded Boldin to the 49ers before the 2013 season.
Smith, 26, is one of the top deep threats in the NFL even though he hasn't developed into a No. 1 receiver. Since 2011, when he was drafted in the second round by the Ravens, his 44 catches of 25 yards or longer tie for seventh in the league.
Though the deal has not been officially announced, Smith took to Twitter to celebrate his new home.
His speed makes it tough on defenses. His 16.9 yards per catch over that span ranks first in Ravens history, and he frequently draws pass interference penalties.
Consistency has been the biggest knock on Smith, who has caught more than 50 passes just once in his NFL career (65 in 2013). He hasn't become a polished route runner or dependable pass-catcher. Last season, he had a career-worst 49 receptions and dropped 11 passes, which tied for second-most in the NFL.
Smith has shown flashes of being a playmaker. He finished 2014 strong with 10 touchdown catches in his last 11 games. Only three receivers (Dez Bryant, Odell Beckham Jr. and Mike Evans) had more over that span.
Also Tuesday the 49ers re-signed backup quarterback Blaine Gabbert to a new two-year, $2 million contract, sources told ESPN's Chris Mortensen and Josina Anderson.
Gabbert played in one game last season,going 3 for 7 for 38 yards and a touchdown. He is a 2011 first-round pick by the Jaguars who was traded to the 49ers for a late-round pick last offseason.
ESPN.com Ravens reporter Jamison Hensley contributed to this report.
49ers Sign Torrey Smith
Chris Mortensen and Bill Polian break down the 49ers' decision to sign WR Torrey Smith.