The league's basement side Huesca were facing Madrid for the first time in their history, but despite impressing for long stages, the hosts were undone by a first-half Gareth Bale volley.
Real are now just two points off second-placed Sevilla and third-placed Atletico Madrid, while they have moved to within five points off division leaders Barcelona once again.
The first opportunity of the match fell to Huesca in the seventh minute, but central defender Xabier Etxeita could only send his header from a dangerous position wide of the away side's post.
Less than one minute later, Madrid made the breakthrough. The assist came from Alvaro Odriozola down the right, with the defender delivering a pin-point cross onto the boot of Bale, who cushioned an excellent volley into the bottom corner of the net.
Huesca were not disheartened though, and a strike from Ezequiel Avila looked to be finding the back of the net in the 17th minute, only for Los Blancos goalkeeper Thibaut Courtois to make a smart save.
Aleksandar Jovanovic had to keep out a powerful Bale strike in the 25th minute as Madrid looked for a second, but the home side continued to cause problems down the other end.
As it transpired, just one goal separated the two teams at the break, but Huesca really should have been level in the early stages of the second period.
Indeed, first-half substitute Gonzalo Melero was presented with a golden chance to head home from close range, but somehow missed the target.
Huesca were firmly on top in the early stages of the second half as they continued to commit players forward, with Cucho Hernandez causing Real Madrid's defensive unit problems.
David Ferreiro brought a smart save from Courtois in the 57th minute as Huesca came close once again, while Madrid just could not muster anything down the other end of the field.
Jovanovic did have to keep out a strike from Bale just past the hour, but that was a rarity as Huesca continued to look the most likely to score the game's second goal.
The Huesca goalkeeper again denied Bale 20 minutes from time, but the visitors were finding it difficult to raise their game against the league's basement side.
As it turned out, Bale's first-half volley was enough to secure all three points on an afternoon where Huesca, who had a couple of half-chances from set pieces late on, were desperately unlucky not to take something from the match.
HUESCA (5-3-2): Jovanovic; Miramon, Insua, Pulido, Etxeita, Ferreiro (Gurler 76'); Rivera, Aguilera (Melero 19'), Gomez; Chimy (Longo 85'), Hernandez
REAL MADRID (4-3-3): Courtois; Carvajal, Ramos, Varane, Odriozola; Modric (Isco 66'), Llorente, Ceballos (Valverde 58'); Bale (Asensio 76'), Benzema, Vazquez