Javi Galan fired Huesca into a shock lead before Varane equalised for the reigning champions.
France defender Varane then tapped home a late winner for the visitors.
Varane said later: “It's a hugely important win. When Huesca were piling the pressure on we were able to dig in and go on to win it. We know we're in a tough spell, with a lot of injuries, and that's our reality at the moment. We have to accept it and our aim is to win our upcoming games.
“I'm happy, it's been a long time since I scored for Madrid. I always try and help the team and today I managed to do so with a brace, I'm really pleased. When we're going through a rough patch and we go a goal down we have to show real character. You have to keep believing until the end. That's why I pushed up top today and the goals went in for me."
On Real's confidence, Varane added: “That's a team thing, we ran for each other today and during the difficult moments we refused to let our heads drop. We kept on with the intention of winning the game and asserting control.
"We have to change our run of form and that comes by winning games and staying positive. Confidence also helps a great deal, which makes today's victory all the more important."