Manager Zinedine Zidane named a strong starting XI for the match and saw his side take the lead on 18 minutes through Bale's low shot from inside the penalty area.
Unionistas threatened an upset when they equalised in the second half through a good run and finish by substitute Alvaro Romero.
The equaliser brought a quick response from Real Madrid, who restored their lead five minutes later.
Marcelo's cross in from the left caused chaos in the penalty area and was bundled over the line by Unionistas defender Juan Gongora as he tried to clear.
Real Madrid added a third deep into stoppage time when Brahim Diaz burst forward and fired a shot across goal for his first of the season.
Real Madrid started with Bale, top scorer Karim Benzema and Vinicius Junior in attack but had to wait until the 18th minute to open the scoring.
Marcelo's cross into the box from the left wing was met by Unionistas defender Gongora, but he could only clear it as far as a lurking Bale. The Welshman took a touch and then went for goal, his shot taking a slight deflection on its way past goalkeeper Brais Pereiro:
The hosts almost hit back straight away. Gongora tried his luck with a swerving effort from range, but a diving Alphonse Areola made a great save to keep the ball out.
Real Madrid went close to adding a second on 36 minutes. Casemiro sent James Rodriguez through on goal and the Colombian put an effort onto the crossbar from a tight angle.
James had another golden opportunity at the start of the second half. Bale's cross from the right was touched on by Benzema to the far post, but James was denied by a strong hand from the goalkeeper.
Real Madrid were made to pay for not extending their lead when Unionistas equalised just before the hour mark. Alvaro Romero took advantage of a slip by Eder Militao to pick up possession, sprint 40 yards and hammer an effort into the roof of the net.
The goal seemed to spark Los Blancos into life and they restored their lead minutes later. Marcelo's cross into the penalty area found a slipping Diaz at the far post and was forced over the line by Gongora.
Real Madrid then needed Areola to make a good save to preserve their lead. A sweeping Unionistas attack culminated in the goalkeeper saving Carlos de la Nava's effort from a Guille Andres cross.
Los Blancos should have wrapped the game up on 84 minutes. Diaz hit the post with a shot, while Vinicius and Luka Jovic were both denied on the follow-up by Pereiro.
The visitors had to wait until stoppage time to finally secure the victory. Diaz raced past Gongora and Romero before stroking home the third to seal Madrid's progress.
Real Madrid play away to Real Valladolid on Sunday in La Liga. Unionistas are in action on the same day against Alaves II in Segunda Division B.