Stuani buried a last-gasp header into the bottom right after a fine cross from Sergio Garcia.
Braces from Espanyol’s Joan Verdu and Rayo’s Leo had seen the match tied at 2-2.
Verdu put the hosts ahead on 11 minutes, his 63rd-minute leveller sandwiching Leo’s double either side of half time.
Both sides were down to 10 men by the time Stuani struck, with Espanyol’s Diego Colotto dismissed on 81 minutes and Rayo’s Mikel Labaka given his marching orders on 68 minutes.
Espanyol now sit in 19th in the table with a record of one win, five losses and two draws. Rayo Vallecano are in 12th place with a record of three wins, four losses and one draw.
Espanyol attempted eight shots, including seven on target.
Rayo Vallecano attempted seven shots, including six on target.
Espanyol and Franjirojos ended the first in a near even split in terms of ball possession, a stat that was reflected in the 1-1 draw at the break.
Both sides had five shots in the first half, and Periquitos put three attempts on goal compared with three for Rayo Vallecano.