Ramis needed to be substituted shortly after because of the lingering effects of a knee injury he appeared to suffer near the end of the first half.
Los Blancos' three points over Eibar lifts them four points clear of fourth-placed Valencia having played a game more; a gap which could be reduced to one - with Los Che Els Taronges leading 1-0 at Sevilla at the time of writing.
They were below their best and rode their luck late on when Eibar should have converted a pair of excellent chances.
The home side restored parity five minutes into the second half when Iván Ramis headed home from Leon's cross.
But he returned just in time to see in-form Cristiano Ronaldo grab his second goal of the match - and 33 of the season - to secure a 2-1 victory.
Just before the break, Ronaldo forced a stunning stop out of Dmitrovic after his 20-yard strike was deflected on goal, with Sergio Ramos sent a free header wide of the post from no more than 10 yards out.
Real responded immediately with a good passing move resulting in Modric laying off for Ronaldo but his effort flew over the crossbar, before the Croatian dragged another shot wide of the post after a driving run.
The irrepressible striker had the final say, however, meeting a cross from Dani Carvajal in the area and powering the ball beyond the Serbian goalkeeper in the 84th minute, scoring a 13th goal in his last seven games in all competitions. His whipped cross found the leaping Ronaldo and the Portuguese made no mistake.