The result leaves second-place Real seven points behind Barca with three LaLiga games to play.
Afterwards, Ancelotti said: “In a game at this level, you have to defend and attack well. We attacked well, looking for chances. Obviously, we could have done better in the first half, we made some obvious mistakes that cost us goals.
"We had to defend better. In today's game, it was quite obvious that we defended badly and it's not because we had a low block. We gifted them some chances and they punished us.
“We had the chance to make it 4-4 twice. It was a competitive, hard-fought and evenly matched game until the last second. We didn't equalise because of an offside. I saw two great teams. There is nothing to call out in terms of attitude and commitment. It didn't go well, but we competed until the end."
Asked if it was the last El Clasico of his career, Ancelotti was coy.
He said, “It's the last one of the season. There are three games left and we have to try to win all three."
On Vinicius Jr and Mbappe
Meanwhile, Ancelotti also explained the substitution of Vinicius Jr late into the game.
“I made the change because he had a sprained ankle. He tried to carry on, but it was bothering him and I preferred to change him."
On Kylian Mbappe and his hat-trick, Ancelotti said: “He did well. Up front, we had chances and they were all very clear. We attacked well, getting in behind them, avoiding offside. We scored three and two were offside.
"Offensively, the team had a clear idea. We could have defended better in the first 30 minutes of the first half, but we mustn't forget that we were missing five defenders.”