It appeared that the points would be shared after Youssef El Arabi cancelled out a first-half goal from Karim Benzema, but Modric found the top corner in the latter stages to keep Los Blancos' title hopes alive.
It is Real Madrid's first away win in the league since November and the success has moved Zinedine Zidane's side to within four points of leaders Barcelona, although the Catalan outfit still have a game in hand.
© Getty Images
Granada started on the front foot, but the first half-chance of the match fell to Real Madrid in the eighth minute. Dani Carvajal drove down the right before picking out Benzema, but the in-form striker's overhead kick was always moving wide of Andres Fernandez's post.
Granada had the ball in the back of the net in the 10th minute when on-loan Watford striker Adalberto Penaranda converted from close range, but the striker was in an offside position after Real Madrid goalkeeper Keylor Navas had come out to clear a through-ball.
Cristiano Ronaldo had a chance of his own in the 14th minute, but the attacker's low strike just flashed wide of the far post during what was an end-to-end period of the match. Indeed, Isaac Success came close for the hosts two minutes later, but like Ronaldo, he saw his effort flash wide.
Real Madrid had another opportunity in the 24th minute when Modric beat the offside trap before delivering a low cross towards Ronaldo, but Levante centre-back David Lomban came from nowhere to make a fine clearance.
The visitors made the breakthrough on the half-hour mark, however, when Carvajal drove down the right before squaring for Benzema, who tapped home to score in his sixth successive league match.
Levante twice came close to an equaliser early in the second period, but Success saw his low strike deflected wide of the post, before Navas kept out a powerful header from Barral.
Modric came close down the other end after striking a rising ball outside the box, but Fernandez made a smart stop. That was far from the end of the chances inside the first 10 minutes of the second half, however, with Rochina and Benzema also coming close to adding to the scoresheet.
Benzema had a golden chance to send his team two goals ahead just before the hour after collecting a through-pass from Modric, but Fernandez was on hand to make a world-class save.
Granada drew level on the hour when Rochina robbed Modric of possession before feeding El Arabi, who slid the ball under the onrushing Navas just two minutes after entering as a substitute.
The expected response from Real Madrid did not really arrive, although Sergio Ramos headed a Modric corner over the crossbar 20 minutes from time.
El Arabi again had the ball in the back of the net in the 71st minute, but the striker was in an offside position when he converted from the second phase of a corner.
Granada were punished for retreating in the final five minutes, however, when Modric worked a yard outside the box before finding the top corner to break the home side's hearts.