NATIONAL HARBOR, Md. -- The best way to put out a dumpster fire? Hire a really good fireman. And that’s exactly what the San Francisco Giants have done.

They have reached an agreement with free-agent closer Mark Melancon. The deal is pending medical review, but Buster Olney reports Melancon’s contract will be for four years and $62 million. The largest free-agent contact ever given to a closer (for now anyway, until Aroldis Chapman and/or Kenley Jansen sign somewhere), it’s money well spent for a Giants team that blew more leads than Inspector Gadget.

In 2016, the G-Men were credited with 30 blown saves, most in the majors. That doesn’t even include the playoffs, when they botched ninth-inning leads in the final two games of the NLDS, including an almost unthinkable four-run implosion in the deciding Game 4 against the Cubs. No wonder GM Bobby Evans is willing to make it rain on Melancon.

A three-time All-Star, Melancon has arguably been baseball’s most dependable closer since taking over as Pittsburgh’s guy at the beginning of the 2014 season. Since then, his 131 saves are the most in baseball. Over that same span, he has pitched to a 1.93 ERA and a 0.90 WHIP that are both among the best in the game. Last season, after coming to Washington at the trade deadline, Melancon picked up right where he left off in Pittsburgh, posting a 1.82 ERA and notching 17 saves in 18 tries, and helping the Nationals run away with the NL East title. Needless to say he’ll be a welcome addition to a Giants team that, despite all its late-game implosions, still managed to win 87 games and make the postseason.

As for the Nats, who were interested in re-signing Melancon, they’ll now have to look elsewhere for a closer. Neither Chapman nor Jansen, the top two free-agent relievers on the market, will come cheap, with their contracts expected to approach an annual average value approaching $20 million. Given that skipper Dusty Baker is intimately familiar with Chapman from their time together in Cincinnati, it wouldn’t be a surprise to see the Nats make a strong play for the former Cubs closer.