The 49ers’ most hated opponent will be suiting up in red and gold come September.

San Francisco did what might have been unthinkable before this week, agreeing with former Seahawks cornerback Richard Sherman on a three-year deal just a day after Seattle disbanded the “Legion of Boom” by releasing him.

NFL Media is reporting it’s worth $39 million with a $5 million signing bonus.

Kyle Shanahan and John Lynch’s latest addition comes at the most glaring position of need on defense. The 49ers entered the offseason with only one clear starter at cornerback, second-year player Ahkello Witherspoon, needing to find another to fortify the 24th-ranked passing defense from 2017.

Sherman, who turns 30 later this month, has been one of the best cornerbacks in the NFL throughout his career. But he’ll have to answer key questions about his health and ability to bounce back from a potentially career-altering injury.

He suffered a torn right Achilles in November, ending his streak of 117 games played in the regular season and playoffs since entering the league as a fifth-round draft pick in 2011.

Prior, Sherman was named a first-team All-Pro three times (2012, 2013 and 2014) and to four Pro Bowls. He has 32 career interceptions and 104 pass break ups in 105 regular-season games. No defensive back drafted since 2011 has more interceptions. San Francisco tied for the fifth-fewest interceptions in the NFL last season (10) and had just three from its top three cornerbacks.

Perhaps’ Sherman’s most famous play, of course, was when he tipped away Colin Kaepernick’s pass in the final moments of the 2013 NFC title game, thwarting the 49ers’ comeback attempt and chance at a second straight Super Bowl appearance. The Seahawks wound up trouncing the Broncos two weeks later, 48-3, to give Seattle its first and only Lombardi Trophy.

The fit with the 49ers is logical as Sherman solidifies the next step in his career. He’s from Compton, Calif., played locally at Stanford and will have a chance to play his former team twice a year.

Additionally, the 49ers’ defensive system has been built to resemble the Seahawks’. Coordinator Robert Saleh was a defensive assistant in Seattle at the height of the rivalry with San Francisco from 2011 to 2013. Sherman (6-foot-3, 195 pounds) in many ways is the cornerback template for the scheme that has gained popularity in the NFL.

The 49ers last offseason joined the Falcons, Jaguars and Chargers as teams that run a similar aggressive Cover-3 system the requires cornerbacks with traits similar to Sherman’s, most notably height and length to disrupt receivers at the line of scrimmage.

The move for Shanahan and Lynch signals that San Francisco considers itself a playoff contender after winning five straight games to end 2017 with Jimmy Garoppolo at quarterback. Additionally, adding Sherman allows the 49ers flexibility in next month’s NFL draft with their starting cornerbacks solidified.

The team had some $50 million in cap space prior to Sherman’s agreement. The new league year begins Wednesday with the free agent negotiating window officially kicking off Monday.