The Italian's team thrashed Almeria 4-0 at home on Sunday, hours after Barca had been edged 1-0 at Granada.
Real (79 points) jumped above Barcelona (78) and into second, behind city rivals Atletico Madrid (79) on head-to-head record with Diego Simeone's men facing Getafe on Sunday.
Ancelotti was surprised by Barcelona's defeat but said there would be several more shocks to finish the campaign.
"Barca can still win La Liga because there are many surprises left. They will fight until the end. This won't affect their performance on Wednesday (in the Copa del Rey final)," he said.
"I'm surprised they lost because they have more quality than Granada. Now, all the teams are playing for something and it's dangerous."
Angel di Maria opened the scoring for Real on 28 minutes before Gareth Bale, Isco and Alvaro Morata added second-half goals.
Ancelotti was pleased with his side's display and refused to look too far ahead with five league games to play.
"We played a good game - good football. The goal was to win because there is very little left in the season," he said.
"We have to win and then do the math. It's a very, very dangerous league because every game is difficult.
"In our heads, we aren't thinking about how things will look for the final game.
"We have very important games ahead of us and we're not thinking about anything else."
Ancelotti is unsure if Cristiano Ronaldo will be fit for his side's Copa del Rey final clash against Barcelona on Wednesday after the Portuguese suffered a setback in his recovery from a hamstring injury.
Di Maria will have a big role to play if Ronaldo is unavailable and the attacker said he was ready to play out wide or through the middle.
"I feel very comfortable on both sides," the Argentine said.
"Today, I went up near the penalty area. I wanted to score, it's been a while since I last did and in the middle, I'm trying to help a little more on defence."
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.