Despite the victory, Zidane's men remain 12 points shy of league leaders Barcelona and four short of Atletico Madrid, and they have played a game more than both of their rivals.
The incident came after 30 minutes at the Ipurua stadium as Los Blancos squeezed past Eibar 2-1.
Isco and Casemiro formed the top and tail of a midfield diamond.More news: New McLaren hybrid hypercar will be company's fastest ever
A sloppy pass out from the back by Anaitz Arbilla conceded possession to Modric, who quickly picked out Ronaldo.
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.
However, Eibar managed to level matters five minutes into the second half when Iván Ramis powered a header into the bottom corner after meeting a cross from Leon.
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.
Eibar defender Ivan Ramis had seemingly done enough to secure a point for the home side that would have left their visitors trailing second-placed Atletico Madrid by six points, but Ronaldo struck in the 84th minute to rescue the win and ensure Valencia can not leap above them later on Saturday.