Real Madrid kept in touch with the La Liga front-runners after they ran out narrow 2-1 victors over strugglers Granada at Estadio Nuevo Los Carmenes on Sunday night.
Los Blancos broke the deadlock on the half-hour mark when Karim Benzema tapped home from close range following good link-up play between James and Dani Carvajal to set him up.
Cristiano Ronaldo had earlier wasted a chance to open the scoring after being played through on goal by James, but the forward pulled his shot wide.
Benzema looked certain to double the visitors' lead just before the hour mark when he controlled Luka Modric's through-ball and got a shot off, but Andres Fernandez pulled off a brilliant save to deny the striker.
That stop proved important as the hosts equalised on 60 minutes through Youssef El Arabi, who fired a low shot past Keylor Navas after being picked out by Ruben Rochina.
El Arabi then thought he had given Granada the lead after corning from a corner, but the goal was ruled out for offside, and more drama was to come late on as Modric netted with a rasping drive from outside the area to clinch all three points for Zinedine Zidane's men.
Real remain in third place, one point behind neighbours Atletico Madrid and a further three adrift of leaders Barcelona, while the Nazaríes are down in 19th position, two points from safety after back-to-back defeats.
Elsewhere, Gary Neville's struggles at Valencia continued after his side lost 1-0 to Real Betis at Estadio Benito Villamarin earlier in the day.
Los Che were punished for poor defending on 49 minutes when Ruben Castro opened the scoring for the hosts and things got worse for Neville's side when Jose Luis Gaya was dismissed five minutes from time.
Shkrodan Mustafi was then denied a stoppage-time equaliser when his header was ruled out for offside as Neville's winless start in the league stretched to 10 matches.
Celta Vigo and Sevilla could not be separated after their clash at Balaídos ended in a 1-1 draw,
Los Rojiblancos recovered from the 25th-minute dismissal of Federico Fazio to take the lead through Daniel Carrico two minutes before half-time when he scored on the rebound after Fernando Llorente's header had been blocked on the line.
But Os Celticos were back on level terms on 64 minutes as Claudio Beauvue slotted home from inside the area after being played in by Daniel Wass.
Unai Emery's side remain fifth in the standings, eight points adrift of Champions League football, while Celta are just two points further back in seventh place.
Real Betis 1-0 Valencia
Celta Vigo 1-1 Sevilla
Granada 1-2 Real Madrid