Bob Melvin will leave the San Diego Padres to become the manager of the San Francisco Giants, sources have confirmed to ESPN.

San Diego granted Melvin permission to interview with the division rival Giants earlier this week, paving the way for the end of a contentious two-year relationship between the Padres and the three-time Manager of the Year.

The Padres said earlier this month that they intended to retain Melvin and general manager A.J. Preller, even after going just 82-80 en route a third-place finish in the National League West.

Melvin managed the Padres for two seasons, reaching the 2022 NL Championship Series but then missing the playoffs this season with a $258 million payroll, the third highest in the majors. He will replace Gabe Kapler, who went 79-83 this season.

The Giants’ plan to hire Melvin was first reported Tuesday by The Athletic. He is expected to be introduced as Giants manager as early as Tuesday night, according to multiple reports.

Melvin will be returning to the Bay Area, where he grew up, played for the Giants and then managed the Oakland Athletics from 2011 to 2021. He went 171-153 with the Padres and will enter his 21st season as a manager next year with a career record of 1,517-1,425 in stints with Arizona, Seattle, Oakland and San Diego.

Giants president of baseball operations Farhan Zaidi had hoped to find a manager by the start of free agency to replace Kapler, who was fired after going 295-248 over three-plus seasons and leading San Francisco to a franchise-record 107 wins in 2021.