It was supposed to be an impossible task but substitute Sergi Roberto who had not scored in 18 months proved to be the winner for Barcelona as he scored the sixth goal in the fourth minute of added time to take Barcelona through 6-5 on aggregate.
Two goals in the first half and an early penalty in the second from Lionel Messi seemed to say the Catalans were going to score the four goals they needed.
But on 62 minutes, Edinson Cavani scored the away goal that should have taken them through.
And for the next 26 minutes, it seemed that Luis Enrique and his players had given up the fight, but two goals from Neymar in the 88th and 90th minutes saw the team re-energised.
The miracle became a reality when Roberto lifted the ball over Kevin Trapp to make it six goals on the night.
If there was ever a team to achieve this first-ever feat of overturning a 4-0 first leg deficit then it must be a team that contained Lionel Messi and his magic stardust.
In the second match of the day, Borussia Dortmund overturned a 1-0 first leg deficit to Benfica as they scored four goals without reply. Pierre-Emerick Aubameyang scored a hat-trick and Christian Pulisic scored the fourth.