The wild ending gave the Royals their fourth consecutive victory.
Jonathan Broxton came on for the Royals in the ninth in hopes of protecting Kansas City's one-run lead and he quickly retired the first two batters.
Greene reached on an infield single and attempted to steal second. That attempt was successful when Quintero's throw sailed into the outfield.
Greene quickly hopped up, sped to third and tried to score. Shortstop Alcides Escobar ran down the errant throw and fired it to Moustakas, whose relay to Quintero was in time to get the runner and end the game.
Kansas City took a 3-0 lead into the bottom of the seventh with two of those runs coming on a single in the third and a sacrifice fly in the seventh by Jeff Francoeur.
Matt Adams then doubled home a run for St. Louis in the seventh and scored on a single by Shane Robinson.
Vin Mazzaro (3-1) was credited with the win after throwing six shutout innings. Broxton recorded his 16th save.
All three Kansas City runs came off Kyle Lohse (6-2), who allowed 10 hits in seven innings.
Gal Gadot cast as Wonder Woman for 'Batman vs. Superman'
Exploding whale video goes viral on Internet