The deal is worth $40 million, including $22 million guaranteed, sources said.
Smith, who has played his entire four-year career with the Baltimore Ravens, follows WR Anquan Boldin to 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.
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.
ESPN.com Ravens reporter Jamison Hensley contributed to this report.