The San Francisco Giants landed the top-tier closer they have been seeking for months, agreeing to a four-year, $62 million contract with right-hander Mark Melancon on Monday.

It's the richest contract ever for a closer, topping Jonathan Papelbon's four-year, $50 million deal with the Phillies from 2012-15 and Mariano Rivera's $15 million annual value total in 2011-12 with the Yankees. But that record isn't expected to last long. Fellow closers Aroldis Chapman and Kenley Jansen are set to sign new contracts this offseason.

"Really excited to have Mark,'' Giants manager Bruce Bochy said in a text message. "Got to know him on a trip to Taiwan in 2011. Fills an important need for us. Great to get one of the premier closers in the game.''

Pending a physical, the pitcher will receive a $20 million signing bonus, $8 million of which is deferred, then salaries of $4 million in 2017, $10 million in '18 and $14 million in each of the '19 and 2020 seasons. He has a full no-trade clause and the chance to opt out after the first two years.

With the bullpen largely to blame for their postseason demise -- and for the team's collapse during the second half of the season -- the Giants have prioritized the acquisition of an established closer for the 2017 season.

The Giants' bullpen failed to hold a 5-2 lead in the ninth inning of Game 4 of the National League Division Series against the Chicago Cubs, with five relievers unable to finish the game in an eventual 6-5 loss that ended their season.

"Adding a premier closer was our main priority this offseason,'' general manager Bobby Evans said. "Mark solidifies the back end of our bullpen and fills a critical role. He brings talent, leadership and experience to our pitching staff.''

Mark Melancon converted 17 of 18 save opportunities for the Nationals after the team acquired him from the Pirates. Chris Williams/Icon Sportswire

Melancon, 31, was acquired by the Washington Nationals at this season's trade deadline from the Pittsburgh Pirates, giving Washington a consistent solution to its closer problem, in contrast to the performance of usurped Washington closer Papelbon.

Melancon finished with a combined 47 saves and 1.64 ERA in 71 1/3 innings over his 75 appearances, having converted 30 of 33 save opportunities for the Pirates last season and then 17 of 18 for the Nationals.

The trade from Pittsburgh to Washington for left-handed reliever Felipe Rivero and pitching prospect Taylor Hearn was the fourth of Melancon's career.

He was traded from the New York Yankees to Houston at the 2010 deadline, from the Astros to the Red Sox in the winter of 2011 and from Boston to Pittsburgh in the winter of 2012. As an eligible free agent, the righty made $9.65 million last season.

Melancon led the majors with 51 saves in 2015.

Nationals GM Mike Rizzo, speaking at baseball's winter meetings in National Harbor, Maryland, said Washington made an offer to Melancon.

"We gave him an offer that we felt was market value and what we were comfortable giving him. You're talking about one of the elite closers in the game and a great teammate,'' Rizzo said. "Conducted himself perfectly as a Washington National. At the end of the day, the Giants offered him more, and he took the deal. That's what free agency's all about. ...

"They've got themselves a great citizen and a great pitcher.''