Zidane's much-changed team dictated the tempo for most of the first half, with Sevilla's set-up focusing on the pace available to them on the break.
But for all their possession, Madrid struggled to craft goalscoring opportunities and Sevilla nearly broke the deadlock 12 minutes in – Franco Vazquez's first-time effort was deflected wide by Ramos.
The former Sevilla man was helpless 14 minutes later, though. Nico Pareja's long ball from the back was flicked on by Luis Muriel to Ben Yedder, and he held off Ramos before coolly slotting through Kiko Casilla's legs.
Sevilla doubled their lead on the stroke of half-time – Steven N'Zonzi showing great awareness to tee up Layun after having a shot blocked, with the Mexican calmly finding the top-right corner.
A clumsy Franco Vazquez challenge on Lucas Vazquez gave Madrid the chance to pull one back from the spot before the hour mark, but Ramos smashed his effort against the bar.
Sevilla were not made to rue missing further chances after that, as Gabriel Mercado marched into the area in the 84th minute and saw his low cross deflected beyond Casilla by Ramos.
Mayoral - who came on for Dani Ceballos with 20 minutes remaining - got Madrid on the scoresheet when he met Marco Asensio's cross with a brilliant header into the bottom-left corner.
The visitors were awarded another penalty when Mercado was adjudged to have shoved Theo Hernandez inside the box, and Ramos fired home in the 95th minute.
It was too little too late for Madrid, though, meaning they now face an uphill battle to finish second.