CSKA Moscow stunned a much-changed Real Madrid with a 3-0 victory at the Santiago Bernabeu on Wednesday, but still finished bottom of Champions League Group G as Viktoria Plzen beat Roma.
The Russian side, who also downed Real 1-0 in the reverse fixture, had to better Plzen's result to finish third and qualify for the Europa League.
But Plzen edged out Roma 2-1 in the Czech Republic to render CSKA's famous victory ultimately meaningless.
Holders Real had already progressed to the last 16 as group winners, with Roma through in second place.
Home coach Santiago Solari boosted CSKA's hopes before kick-off by making seven changes to the starting XI which beat Huesca 1-0 in La Liga at the weekend, leaving Gareth Bale, Luka Modric, Raphael Varane and Toni Kroos on the bench.
Real's youngsters started brightly, with Vinicius Junior forcing visiting goalkeeper Igor Akinfeev into a fine-one handed save, and Marco Asensio then curling the ball against the crossbar.
But Viktor Goncharenko's CSKA claimed a shock lead in the 37th minute, as Fedor Chalov danced through the makeshift Madrid defence and bent a left-footed shot into the corner.
Georgiy Schennikov volleyed home shortly before the interval after an excellent team move to leave Real facing an embarrassing loss.
At half-time Solari sent on Bale, the two-goal hero of last season's final triumph over Liverpool, with Kroos following soon after.
But it was CSKA who extended their advantage, as Arnor Sigurdsson fired low past Thibaut Courtois in the Real goal with 17 minutes to play.
It mattered little though, as Plzen secured a place in the Europa League last 32 thanks to Tomas Chory's 72nd-minute winner against Roma.
Midfielder Jan Kovarik tapped in to break the deadlock in the 62nd minute, only for Turkish youngster Cengiz Under to level for Roma midway through the second half.
But Plzen extended their European campaign when Chory headed in after Kovarik's volley was pushed out by Antonio Mirante.
Teenage midfielder Luca Pellegrini was sent off in injury-time after picking up two bookings in quick succession, as Roma's winless run in all competitions stretched to five games.