Jacobo Ramon struck an injury-time winner for Real in a game which marked the first since Ancelotti had announced he would be leaving his job to take charge of Brazil at the end of the season.
The Italian said afterwards, "The team fought hard and played with intensity, especially in the second half. We thoroughly deserved the victory. Everyone made a huge effort and we're pleased because we want to finish the season well.
"The game didn't start well, but after that the team did really well in all respects. They didn't give up despite the difficulty. Having 12 players injured is quite rare and we managed to make up for the loss of some very important players with a good collective attitude. I've never seen a team shoot 40 times at goal like we did today.
“Whenever I sit on the Bernabéu bench, it's always special. It has been a special night like all the others."
We'll keep fighting
The result, which also saw Kylian Mbappe on the scoresheet, keeps the LaLiga title alive, with leaders Barcelona not yet confirmed champions.
Ancelotti also said, “The team was amazing tonight. We put in an extraordinary effort. If we had done that in every game, it might have been a better season.
“We want to do our job, which is to win the next matches and see what happens. Our task today was not to give away the league. They'll have to play tomorrow. Anything can happen in football. If they win, we'll congratulate them and if they don't, we'll stay in the fight.”
He added, “The day I leave Real Madrid I will leave with the peace of mind that I've done everything I could've done. I've had a great time. Football doesn't end and I hope my teams can try to win until the last second, as we have always done here.”