49ers sign WR Torrey Smith

Free-agent wide receiver Torrey Smith has signed a contract with the San Francisco 49ers, the team announced Wednesday.

The five-year deal is worth $40 million, including $22 million guaranteed, sources told ESPN's Adam Schefter and Adam Caplan on Tuesday.

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.

Before the deal was officially announced, Smith tweeted in celebration of it Tuesday.

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 was 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 and 49ers reporter Paul Gutierrez contributed to this report.