Cornerback Richard Sherman, the 49ers’ biggest nemesis for most of the past decade, is reportedly joining the organization he tormented for so long.

For the 49ers, the reasoning seems to be, “If you can’t beat ‘em, sign ‘em.”

Sherman and the 49ers agreed on a three-year contract Saturday, a source confirmed. Sherman told ESPN the deal is worth up to $39.15 million.

Sherman’s seven-year union with the Seattle Seahawks came to an end on Friday, as the club released him to avoid playing his scheduled $11 million salary for the 2018 season.

He had dinner Friday night with 49ers coach Kyle Shanahan and spent most of Saturday with club officials in Santa Clara. He also took a physical. Sherman represented himself in negotiations. ESPN first reported the three-year agreement. He told ESPN the contract is worth up to $39.5 million.

Sherman, who turns 30 on March 30, is a four-time Pro Bowl player and a three-time selection as a first-team All-Pro. After playing all 16 games in his first six seasons, Sherman’s season came to an end in November after nine games due to a torn right Achilles tendon.

The original timetable for Sherman’s return to football activity was 6-to-8 months, which would place his return from mid-May to mid-July – in time for the opening of training camp. Dr. Robert Anderson performed the surgery in Green Bay on Nov. 16.

Sherman also recently underwent a procedure to “clean up” his left Achilles.

Since Sherman’s rookie year of 2011, he leads the NFL with 32 interceptions and 99 passes broken up. He has been particularly disruptive – both with his skills and his mouth – against the 49ers.

Sherman made the play in the final minute of the NFC Championship game in January 2014 to deflect a Colin Kaepernick pass intended for Michael Crabtree in the end zone. Linebacker Malcolm Smith, now with the 49ers, made the interception to set up Seattle’s first and only Super Bowl title.

Beginning with that game, the Seahawks have won nine consecutive head-to-head matchups against the 49ers.

The addition of Sherman fills the 49ers’ biggest offseason need. Cornerback Ahkello Witherspoon had a promising rookie season, but the 49ers did not have another starter-caliber cornerback on their roster before the addition of Sherman.

Dontae Johnson, who started all 16 games at cornerback for the 49ers last season, is scheduled to be an unrestricted free agent. The 49ers are not expected to place a high priority on re-signing Johnson.