In front, Real improved but five minutes into the second half and Eibar were level.
Eibar showed no signs of sitting back and nearly went ahead on 82 minnutes but Kike Garcia sent his low strike just wide of the upright.
But he was back on the pitch to see Cristiano Ronaldo score his second goal of the game with what turned out to be the victor.
Ronaldo almost scored his second of the game in the 62nd minute from a delightful Gareth Bale cross but his effort was saved by the Eibar goalkeeper.
First, the unmarked Inui headed over from seven yards out and then Kike hit the side-netting with only Keylor Navas to beat.
Karnataka govt unveils state's flag, to seek Centre's approval
It also has the state's emblem "Gandaberunda" at the centre, but will not have the inscription "Satyameva Jayate, he said". On Thursday Karnataka Chief Minister Siddaramaiah unveiled a new state flag.
Eibar pushed Madrid back in the first half but were made to pay for a mistake on the half-hour when Luka Modric set up Ronaldo to open the scoring.
Modric wanted a penalty for handball on Jose Angel but there was very little in it, as Dmitrovic somehow denied Ronaldo with an excellent one-handed save as the Portuguese connected to a cross from the left from Bale.
It happens to the best of them, just ask Gary Lineker. The Welshmen though glanced his header from the resultant corner just wide of the target. Subs: Nacho Fernandez (for Varane, 28) 5, Karim Benzema (for Kroos, 71) 5, Lucas Vasquez (for Isco, 71) 6.
Eibar continued to threaten though and was nearly in following an under-hit backpass but Navas was out quickly to deny Kike.
CRISTIANO RONALDO scored twice as Real Madrid survived a second-half fightback from Eibar to win 2-1 at the Ipurua Municipal Stadium.
The galloping Ronaldo met an inch-perfect cross from Daniel Caravajal to head home past Dmitrovic.