The 30-year-old had not played since January 4, but was included by Zinedine Zidane in the starting line-up to face third-tier side Unionistas.
The manager was rewarded for his choice when the Welshman scored his third Real goal of the season after less than 20 minutes.
Real did not impose themselves fully on the game, and the home side took advantage, as substitute Alvaro Romero levelled the tie at the start of the second half.
However, Los Blancos’ quality was too much for Unionistas in the end, with Juan Gongora scoring an own-goal for Real to retake the lead.
Brahim Diaz then secured victory for the visitors with his injury-time strike.
Bale put his side ahead in the 18th minute, following a poor headed clearance, the Welshman taking a touch on his chest before hitting the ball, with a deflection taking it past the goalkeeper.
Despite taking an early lead, Real struggled to fully make their mark on the game, dominating possession but failing to create lots of chances to extend their advantage.
James Rodriguez played a clever one-two with Casemiro to put himself in a good scoring positions but his effort just looped onto the crossbar.
Unionistas goalkeeper Brais Pereiro made a sprawling save with his outstretched right hand to prevent Rodriquez from doubling his side’s lead at the start of the second half.
The home side looked to push forward more in the second half, having struggled to get going in the opening 45 minutes.
Against the run of play, substitute Romero levelled the tie just two minutes after coming on. The 23-year-old drove towards the Real defence before firing past Alphonse Areola.
Unionistas were unable to keep the tie level for long, however, with the ball being bundled into the net by home defender Gongora.
Marcelo had sent a low cross towards Brahim who managed to send the ball towards the goal, despite losing his footing, but Gongora only managed to turn it onto his own post before it went over the line.
The home side found themselves in a three-on-two situation, but instead of finding his team-mate, Romero decided to shoot and his effort was straight at goalkeeper Areola.
With the visitors looking to secure the win, two chances fell to Karim Benzema. His first strike was just wide of the target and Pereiro was able to palm away his second effort a few minutes later.
Unionistas won a free kick on the right and when the ball came in it was headed towards his own goal by Dani Carvajal but Areola was able to keep it out and maintain his side’s lead.
In injury time, Real secured their passage to the round of 16 when Brahim weaved between two defenders before scoring.