The Royals had entered the game having lost six of seven and were down, 6-4, in the ninth. But with runners on second and third and one out, pinch-hitter Moustakas, battling a bruised thumb, stroked a two-run single to center off Papelbon, tying the game.
After Alcides Escobar singled Moustakas to third with two out, Cain drilled a line drive to deep left-center to end it.
"People know we are a good team," Escobar said. "We know it in here."
Added Royals manager Ned Yost, "Those are the kind of wins to help you get going. It was a rough week for us. The character of this team ... they never quit, and keep battling. It paid off for them again tonight."
Nationals catcher Wilson Ramos had three hits, including two doubles, one that produced the tying run in a three-run sixth.
Right-hander Chris Young started for the Royals and gave up two runs over 4 2/3 innings. Eric Hosmer drove in three of the Royals' runs.
"This was such a great team win," Young said. "Hopefully it will be a morale booster."
MOMENTS THAT MATTERED Roark roaring on mound: After allowing three runs after three innings, Roark settled down and held the Royals to three hits and one unearned run in the next 4 1/3 innings. It's the third game in a row he has pitched at least seven innings.
"I was able to pick up the tempo a little bit," Roark said about what happened after the third inning. "I got the ball back, went back out on the mound. My tempo was a lot better. I was just executing."
Dyson misplay: The Royals were clinging to a 3-2 lead in the sixth when the Nationals put runners on first and third with one out. Ramos then sent a high drive to deep right that first appeared to be a game-tying sacrifice fly. But right fielder Jarrod Dyson nearly got spun in a circle as it sliced back over the top of his head. Dyson, normally a sound defender, then fell and the ball bounced into the bullpen for a ground-rule RBI double. The next hitter, Danny Espinosa, then grounded out to second, another run scored and the Nationals had a 4-3 lead.
"He gets those, but that was a tough play," Yost said of Dyson. "It was slicing and turned him around."
Three-run sixth puts Nats ahead: The Nats were down, 3-2, when they took the lead against right-hander Luke Hochevar, who had pitched out of a bases-loaded jam in the fifth. Ryan Zimmerman scored the tying run on a double by Ramos, then Werth scored on a groundout by Espinosa, while Ramos touched home plate on a triple by Chris Heisey.
Hosmer delivers: The Royals ended a 27-inning scoreless streak on Sunday. But their new streak reached 12 innings Tuesday before Escobar dropped an RBI single into right-center in the third inning that tied the score at 1. Two batters later, with two outs and two on, Hosmer ripped a two-run single to right-center that gave the Royals a 3-1 lead. Hosmer also got an RBI in the eighth when he beat out a potential double-play ball that allowed the fourth run to score. Hosmer did it with a headfirst slide into first.
"That's just how we play," Hosmer said.
SOUND SMART WITH YOUR FRIENDS
The Royals had gone 46 straight innings without getting multiple runs in an inning before putting up three in the third inning of Tuesday's game.
WHAT'S NEXT Nationals: Right-hander Stephen Strasburg has started the year with four consecutive wins for the first time in his career and has been the Nationals' most dominant pitcher. He enters Wednesday's 2:15 p.m. ET series finale with a 40-to-8 strikeout-to-walk ratio and a 2.25 ERA.
Royals: Right-hander Kris Medlen (1-2, 4.87 ERA) takes the mound in the series finale at 1:15 p.m. CT on Wednesday. Medlen gave up just one hit and one run in his last start, against the Mariners, over 5 1/3 innings.