Zinedine Zidane's side went into the match with a seven-point deficit to leaders Barcelona, and were unable to recapture the form which saw them fire six past Espanyol a week ago.
Karim Benzema put Madrid ahead after half an hour but Granada, who had a goal disallowed for offside in either half, deservedly levelled the match through substitute Youssef El-Arabi, though the visitors were frustrated at some accidental interference on Modric from referee Jesus Gil Manzano.
David Lomban saw a header ruled out for offside as the hosts, who began the match two points from safety in 19th, continued to cause real problems for a Madrid outfit who looked well short of the standards they have hit under Zidane in recent weeks.
Yet Modric turned hero for his side as he rifled in from distance with five minutes to play to move Madrid back to within four points of Barca, who earlier beat Levante 2-0 and have played one game fewer.
Granada impressed in their narrow defeat at the Santiago Bernabeu earlier this season and enjoyed a bright start, with Adalberto Penaranda denied by the offside flag after drilling home at the near post with Keylor Navas caught out of position outside the area.
Cristiano Ronaldo flashed a shot just wide of the far post after being picked out by a fine James Rodriguez pass as Madrid offered a glimpse of their threat in behind the Granada line, and they exploited it to clinical effect on 30 minutes as Benzema opened the scoring.
Dani Carvajal was picked out in acres of space to the right of the area by Isco's pass, and his cut-back was tapped home by Benzema from just six yards out.
Andres Fernandez was on hand in the 56th minute to keep Granada alive in the match, making a superb one-handed save low to his right to deny Benzema after Modric's pass had split the home defence, and they found themselves on level terms just three minutes later.
Modric lost possession in midfield after being impeded by the referee, allowing Ruben Rochina to slide the ball through to El-Arabi, who - having only been on the pitch for two minutes - slotted the ball through the legs of the onrushing Navas and in, despite the best efforts of Carvajal.
Granada thought they had taken the lead when Lomban headed into the bottom corner, though El-Arabi was flagged for offside after attempting to flick the ball home, and Isaac Success had penalty appeals waved away after being brought down by Navas, though replays showed the goalkeeper clearly played the ball first.
The home side looked set for a vital point until Modric collected Mateo Kovacic's pass and blasted an unstoppable shot into the top-left corner from 25 yards to send the visiting dugout into raptures.