For four years, Mark Melancon watched as Mariano Rivera pumped cut fastballs into catchers’ mitts. Melancon and Rivera were teammates on the New York Yankees — only in spring training for the first two years — and Melancon witnessed the ball’s movement, the future Hall of Famer’s legendary ability to confound hitters even when they knew what pitch was coming. All the swings and misses. All the broken bats. Save after save. It was a cheat code.

One spring training a pitching coach named Billy Connors had shown Melancon the grip, a variance from the standard four-seam fastball grip, but he was hesitant to incorporate it. He had heard it could stymie velocity, negatively impact other pitches and hurt your elbow — a scary possibility for someone who had already undergone Tommy John surgery

“I was a little bit cautious,” Melancon said. “I didn’t want to jump right into it.”

Nine years later, Melancon, 31, is one of baseball’s best closers, the prize the Washington Nationals acquired Saturday to replace Jonathan Papelbon and address the club’s most pressing concern. His ascension can be traced to his adoption of the cut fastball, with the help of two teammates.

[Despite Ramos’s big year, Nats haven’t talked extension]

Melancon’s reluctance to adopt the pitch — which in his case burrows in on lefties and swerves away from right-handed batters with late movement — faded after the Yankees shipped him to the Houston Astros as part of a package for Lance Berkman in July 2010. When he got to Houston, the closer was Brandon Lyon.

The right-hander threw a cutter more than anything else, so Melancon began picking his brain. The two would play catch from 30 to 40 feet, and Melancon experimented. Lyon taught him the proper spin and wrist angle.

“Right away I would say it was decent, where he knew it could be a pitch for him that he could use,” Lyon said in a phone interview.

The trial and error lasted for a couple months before Melancon began throwing the cutter in games. Initially he mostly stuck to his arsenal of two-seam fastball, four-seam fastball, curveball and change-up. But by the next spring he was throwing it 20 percent of the time, according to BrooksBaseball.net. The proportion reached 33 percent in September 2011 in his first stint as a closer at the major league level, having replaced Lyon. He compiled 20 saves and a 2.78 ERA.

[Nats reset rotation, won’t use fifth starter this weekend]

Melancon’s use of the pitch fluctuated when he was traded to the Boston Red Sox in 2011 — ranging from 17 percent one month to 38 another — and he struggled. He posted a 6.20 ERA. Then Melancon was traded that winter to the Pirates, one month after Russell Martin had signed with them. Martin was coming off a two-year stint as the Yankees’ starting catcher, a tenure that coincided with the final two seasons of Rivera’s career. At spring training Melancon threw a few cutters to Martin, who told Melancon the pitch reminded him of the one Rivera threw. He insisted Melancon throw it as often as possible.

Melancon said he remained skeptical at first. He wondered whether the pitch was good enough to get hitters out if they knew it was coming. But Martin kept pounding the idea into him, and Melancon emerged from spring training a different pitcher.

“Russ was probably just being nice in that compliment,” Melancon said. “But it gave me a lot of confidence, and he would just put that [signal] down all the time.”

That season he threw the cutter 76 percent of the time. His four-seam usage tumbled from 32 percent the previous season to 7 percent. Melancon became a cutter and curveball pitcher, and the results were startling: He posted a 1.39 ERA while toggling between setup man and closer and made the all-star team.

“You know it’s coming, but it doesn’t matter,” said Nationals outfielder Chris Heisey, who is 2 for 9 against Melancon in his career. “He has pinpoint control, and he throws it where he wants to.”

Melancon was the Pirates’ full-time closer by June 2014 and finished the season with a 1.90 ERA, 0.87 WHIP and 33 saves. Last season he made the all-star team again and amassed 51 saves, the most in baseball. When the Nationals traded for him he had 30 saves, a 1.51 ERA and the most saves in baseball since July 2013.

The breakout also coincided with his use of a heart-rate monitor and a health platform designed to measure various biochemical markers. Melancon wears the heart-rate monitor — a small circular object — on his chest during games with the goal of steadily increasing his rate over the course of the game.

“I slowly want to build up to 100 percent so 100 percent is when I’m in the game,” Melancon said. “I don’t want to go 0 to 100. It’s like if you were to watch a movie and then stand up and try to run a sprint. All we’re doing down there in the bullpen is sitting, watching the game.”

Melancon’s cutter has dipped a bit over the years — from an average of 93 mph in 2013 to 91 mph this season — but its effectiveness never hinged on explosiveness.

Melancon has never piled up strikeouts at a rate consistent with other top closers; nine per nine innings is the most he has posted in a season since he assumed the role. This season, he’s striking out 8.45 batters per nine innings (91st among qualified relievers) and he has yielded a 24.4 percent hard-hit rate (131st). But his walk rate (1.85 per nine innings) is in the top 20, his ERA (1.44) is sixth and his WHIP (0.94) is 21st.

Melancon, a free agent this offseason, is a clear upgrade over Papelbon at a price the Nationals were willing to pay for their postseason push.

“It’s an honor. It’s so cool,” said Melancon, who has made two appearances as a National. “It’s humbling to know that I’m here to win a championship just like everybody else. I think I can help the team. I know sometimes the trade deadline isn’t always fun. Sometimes it can disrupt the team, but I think everybody is on board.”