The European champions, who had already won Group G, named a weakened team.
Fedor Chalov curled home CSKA's opener against the run of play and Georgy Schennikov volleyed in a second after Mario Fernandes' shot was saved.
Icelandic teenager Arnor Sigurdsson completed the convincing win with a strike from the edge of the box.
Real brought on Gareth Bale at half-time and the Welshman suffered an ankle injury, although he was able to play the rest of the game after receiving treatment.
The holders were booed off at full-time by their fans as they suffered a first home Champions League defeat in nine years.
CSKA Moscow, whose only two group wins came against Real, are out of Europe after Viktoria Plzen beat Roma 2-1 to finish third and clinch a Europa League place.
More about: Real-Madrid CSKA-Moscow