The Reds remained six games behind St. Louis, which has won 15 in a row, for the second NL wild-card spot. Cincinnati won back-to-back home games for the first time since sweeping Miami in a four-game series Aug. 19-22.
''That's all we can do,'' Castellanos said. ''The stretch that the Cardinals are on is truly impressive. It gets repetitive, but it is all we can control.''
Facing Patrick Murphy (0-3) in his second inning of work, Castellanos lined an 0-1 pitch to straightaway center field, extending his career-high homer total to 31.
The game-ending homer was the second of his career.
''I was looking to hit a home run,'' said Castellanos, who finished 2 for 3 with three RBIs. ''I'm not going to beat around the bush. Any time a pitcher is in love with his fastball. If he wants to play fire with fire. I love that game.''
''Nick is a big time player,'' Reds manager David Bell said. ''We've seen it all year. What a fantastic season he's had. He's finishing strong.''
Murphy was Washington's fifth relief pitcher of the game. The Reds used seven.
''Murphy came in there and threw well,'' Nationals manager Dave Martinez said. ''He got that first big out in the ninth and then threw a fastball down the middle. He was throwing the ball well. He threw that first curveball to Castellanos and he reached 97 (on the next pitch), but Castellanos is a good fastball hitter.''
NL batting leader Juan Soto went 1 for 3 with two walks for Washington, leaving his average at .324.
Reds reliever Mychal Givens (4-3) escaped giving up a go-ahead homer in the ninth when Keibert Ruiz's towering drive down the right field line landed in the seats just outside the foul pole.
Ruiz and Lane Thomas both hit solo homers for Washington. Thomas went deep to center field for his seventh home run of the season, all since joining the Nationals at the trade deadline from St. Louis for Jon Lester.
Ruiz's drive sailed into the right field seats in the sixth, giving Washington a 6-5 lead with his second homer in two nights.
The Reds tied it in the seventh when Castellanos drew a leadoff walk and scored on Kyle Farmer's double.
Reds rookie starter Vladimir Gutierrez threw 56 pitches and tied his season high with four walks while lasting a season-low 2 2-3 innings. The Nationals reached him for four runs and five hits.
Washington's Erick Fedde gave up five runs on seven hits and three walks in 4 2-3 innings.
The Reds caught a break to score in the third. Nationals left fielder Andrew Stevenson misplayed a flyball by Jonathan India and it bounced into the stands for ground-rule double in the third. India later scored on Castellanos' sacrifice fly.
The two teams have combined to used 28 relief pitchers to cover 22 innings over the last two games.
With Miami losing at Tampa Bay, Washington missed a chance to climb out of last place in the NL East for the first time since August 31.
Nationals: An MRI on INF Carter Kieboom's left forearm was negative and he was available off the bench. He was scratched from Friday's original starting lineup after reporting soreness. He was hit by a pitch on Monday in Miami.
Reds: INF Joey Votto was scratched from the starting lineup with left knee soreness. Tyler Stephenson replaced Votto in the lineup. ... LHP Wade Miley went on the 10-day injured list with a neck strain. LHP Cionel Perez was recalled from Triple-A Louisville.
Nationals: LHP Josh Rogers (2-0) is 3-3 with a 5.47 ERA over 12 total appearances, including seven starts, in 2021.
Reds: RHP Tyler Mahle (12-6) is tied with LHP Wade Miley for the team lead in wins.
More AP MLB: https://apnews.com/hub/MLB and https://twitter.com/AP-Sports
Copyright 2022 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.