The result left Atletico Madrid top of the standings with three games to go on 77 points, two ahead of second-placed Real and third-placed Barcelona. Sevilla are fourth on 71.
Brazilian midfielder Fernando put Sevilla in front midway through the first half after a headed goal from Real striker Karim Benzema had been ruled out for a marginal offside.
Real improved in the second half and deservedly levelled through Marco Asensio in the 67th but the game swung back in Sevilla's favour in an extraordinary turn of events.
Real launched a quick counter and Benzema earned a penalty when he was felled by goalkeeper Bono, but a VAR review led to the referee penalising Real defender Eder Militao for an earlier handball and awarding a spot kick to Sevilla instead.
Former Barcelona midfielder Ivan Rakitic kept his nerve to deceive Thibaut Courtois from the spot and restore Sevilla's lead in the 77th minute but Real somehow stayed alive in an enthralling title race when Toni Kroos tried his luck and saw his shot diverted into the net off the boot of Diego Carlos.