Minutes later, Rayo were presented with the opportunity to draw level from the spot after Alberto Bueno was adjudged to have been felled in the box by Javi Manquillo.
The hosts were to rue their missed opportunity as Arda Turan doubled the Rojiblancos lead, tapping home Jose Sosa's pass from a few yards out moments after the winger's own effort was pushed onto the crossbar by Ruben.
Viera did go some way to making up for his earlier miss from the penalty spot by grabbing a goal for Paco Jemez's relegation-threatened side, converting from close range to give Vallecano a lifeline.
Just minutes later, however, Atletico further strengthened their foothold on the contest in the closing stages of the first half courtesy of a Turan header, with the winger grabbing his second of the game following a Gabi free kick.
Costa added a fourth for the league leaders, with the striker converting Filipe Luis's low cross to score his first goal of the year, though in what was a topsy-turvy battle, Rayo hit back immediately through Joaquin Larrivey's strike.
Atletico managed to hold on to their two-goal advantage to extend the club's unbeaten run to 12 matches, and take top-spot in La Liga ahead of Barcelona's later kickoff.