St. Louis secured no worse than a wild card on Sunday.
Beltran's two-run homer in the fifth off Roark broke a 2-all tie. It was his team-leading 24th of the season and first since Aug. 24.
"The last thing I was thinking about there was a home run," Beltran said. "I've been scuffling a little at the plate, but the way for that to go away is to keep playing and continue to swing the bat."
Wainwright (18-9) gave up three runs and seven hits over seven-plus innings. He struck out five, giving him a career-high 214 on the season.
"This was a great team win. Everybody did their part," Wainwright said.
Jayson Werth hit a two-run homer on the 15th pitch of the game. Wainwright then retired nine in a row and allowed just one run on five hits the rest of the way. He moved into second in the NL in wins behind Washington right-hander Jordan Zimmermann, who has 19.
"The first inning, sometimes great teams are going to put a couple runs together like that," Wainwright said. "The key is to keep pitching and limit the damage."
St. Louis manager Mike Matheny was impressed with the way Wainwright bounced back from the slow start.
"It's amazing that once he gets going, how different his stuff looks," Matheny said. "It doesn't matter what he looks like early, he's going to put it together."
Trevor Rosenthal got two outs for his first career save.
Washington closed to 4-3 in the eighth on singles by Anthony Rendon and Steve Lombardozzi and a groundout from Ryan Zimmerman. St. Louis reliever Carlos Martinez got Werth to ground out with a runner in scoring position to end the threat.
The Cardinals climbed within 2-1 on a run-scoring single by Yadier Molina in the first. They tied it on successive singles from David Freese, Daniel Descalso and Shane Robinson in the fourth.