The Bulgarian side pushed the reigning champion to the brink, but the French striker's late goal saved the result for Los Blancos.
Karim Benzema spared Real Madrid's blushes as his strike secured an unconvincing 2-1 UEFA Champions League win at Ludogorets.
The France striker hit home 13 minutes from time to deny the plucky host its first point in the competition following a superb display of determination from the Bulgarian side.
Georgi Dermenzhiev's men had come within a last-minute penalty of taking a point from Liverpool in its opening fixture and on Wednesday again belied its tag as Group B's underdog.
The host took the lead early - in a clash moved from Razgrad to the Stadion Vasil Levski in Sofia because of stadium needs - through forward Marcelinho.
Real talisman Cristiano Ronaldo then missed a penalty, but atoned for that failure by converting a second spot kick soon after.
Ludogorets refused to lie down following that equalizer and looked set to take a point from an end-to-end contest, only for Benzema to dash those hopes and seal a fifth-straight win in all competitions for Real.
Dermenzhiev's side was rewarded for a fast start to proceedings in the sixth minute as Marcelinho took advantage of Real's continued failings at set pieces. The Brazilian nodded in at the far post after Cosmin Moti had flicked Fabio Espinho's corner into his path in another display of poor marking from the visitor.
Gareth Bale then went close to providing a response, which looked set to arrive in the 10th minute after Yordan Minev conceded a penalty for a foul on Javier Hernandez. But Ronaldo's spot kick was a poor one, allowing Vladislav Stoyanov to preserve Ludogorets' advantage with a save down to his right.
The Portugal forward did put the ball in the net three minutes later with a cool finish into the bottom corner, however, his effort was ruled out for offside.
Yet Ronaldo was not to be denied and he restored parity from the spot in the 24th minute by drawing a foul from Moti in the area and powering beyond the unfortunate Stoyanov, who correctly chose to go the same way he did for the earlier penalty.
Ludogorets remained a threat going forward, though, and Real was grateful to captain Iker Casillas for keeping it level with a strong save on the hour from Mihail Alexandrov.
Real's superiority was apparent by the end of the half, but Ancelotti's men continued to be profligate in front of goal, Hernandez dragging an effort wide three minutes before halftime, with Stoyanov then brilliantly denying Bale seven minutes after the restart.
For all Real's pressure, Casillas was just as busy at the other end, the Real captain producing flying saves from Espinho and Marcelinho.
However, Ludogorets admirable resistance was finally ended as substitute Benzema - brought on for Hernandez - rescued Real by volleying home Marcelo's left-wing cross and a frustrating outing could get worse for the holder, which saw Ronaldo pick up a late ankle injury.