Karim Benzema and Marco Asensio on target in Real Madrid victory
Hakim Ziyech had equalised for the home side in between.
But the reigning champions, seeking a fourth straight title, were given a major scare by the only team left in the competition who had to come through qualifying.
Four-time winners Ajax, in the knockout stages for the first time in 13 years, dominated for long spells.
In a vibrant display they hit the woodwork, tested Thibaut Courtois frequently and had a goal ruled out by the video assistant referee before Benzema struck.
Hakim Ziyech then equalised for Ajax, only for substitute Asensio to grab the winner three minutes from the end.
Real travelled to Holland full of confidence after a 3-1 win against Atletico Madrid at the weekend, their sixth victory in a seven-game unbeaten run.
Onana was in action again after 15 minutes to tip over a fierce angled drive from Brazilian teenager Vinicius Junior.
But Tadic came agonisingly close to breaking the deadlock when he held off Sergio Ramos only to see his shot come back off the foot of a post.
Ajax were by now well on top and another slick passing move put Ziyech through on goal but Courtois came out well to block.
The hosts thought they had taken a deserved lead when, from the corner, Courtois made a mess of claiming a header and Nicolas Tagliafico nodded in the rebound.
However, a lengthy VAR review eventually ruled out the goal with Tadic, marginally offside, standing in front of the Real keeper as the ball looped in.
Early in the second half Benzema tested Onana with a low shot on the tun, before Ajax broke down the other end and David Neres fired too close to Courtois.
But just before the hour mark Benzema made the breakthrough with his 60th Champions League goal on his 450th Real appearance.
Vinicius chased a ball over the top down the left wing and cut inside before finding Benzema, who sent an unerring finish across Anona and high into the net.
Ajax were not finished, though, and with 15 minutes left they sliced Real open again with Ziyech converting a low cross from Neres.
However, Asensio converted the winner when he met a stunning delivery from Dani Carvajal at the far post.