Perez launched a two-run shot in the first inning, handing the Royals a 4-0 lead, but the Nationals scored the next four runs to tie the score.
Eric Hosmer drew an eight-inning walk from Craig Stammen (7-6), Billy Butler singled and Mike Moustakas coaxed another base-on-balls to load the bases. That brought up Perez, whose infield hit to short drove in Hosmer with the go-ahead run.
David Lough followed with another RBI single for Kansas City, which broke a seven-game losing streak.
Kelvin Herrera (5-6) notched the decision and Greg Holland nailed down the win with his 35th save.
Celebrity Breakups and divorces of 2014 [PHOTOS]