After Robbie Gould demanded a trade from the 49ers before the draft, Adam Schefter says the two sides worked out their issues to agree to a deal. (1:02)

Beating Monday's 4 p.m. ET deadline for franchised players to sign long-term extensions, kicker Robbie Gould signed a four-year deal with the San Francisco 49ers, the team announced.

Financial terms were not disclosed, but league sources told ESPN it's a two-year, $10.5 million fully guaranteed contract that, including an option clause, could turn into a four-year, $19 million deal with $15 million guaranteed.

Gould's deal, which his agent, Brian Mackler, and 49ers executive Paraag Marathe have been working on for months, reached a breakthrough over the weekend. At the start of the weekend, both sides thought it would be challenging to get it done, but they reached a compromise Sunday by installing an option clause.

The 49ers have an option in which they can pick up the remaining two years on Gould's contract by the 17th week of the 2020 season, per a source. To do that, the 49ers would have to fully guarantee Gould $2.25 million at that time, then another $2.25 million on April 1, 2021.

The deal includes a $3 million signing bonus and a $3.15 million fully guaranteed base salary this season, then a fully guaranteed $4.35 million base salary in 2020, per a source. If the option is picked up, the deal would include a $4.5 million base salary in 2021 and a $4 million base salary in 2022.

"Over the years, Robbie has established himself as one of the best at his position in the NFL, which is precisely why we were so committed to working out a new contract with him," 49ers general manager John Lynch said in a statement. "I would like to thank everyone who worked so hard to make this deal come to fruition. We are very happy to start off the year on the right foot with this agreement in place so that Robbie can get back with his teammates and focus on making the most out of the upcoming season."

In April, an inability to come to terms on a long-term contract, combined with Gould's desire to return closer to his Chicago home, prompted the kicker to shut down any further contract talks and to formally request a trade. The team said then it wouldn't honor Gould's request.

Gould, 36, had been living in a hotel near the Niners' team facility in Santa Clara, California, the past two years while his wife and family remained in Chicago during the season.

In two seasons with the 49ers, Gould has been one of the league's best kickers, making 72 of 75 field goal attempts. He led the league in field goal percentage (97.1) last season.

ESPN's Nick Wagoner contributed to this report.