Tries from Max Malins (two), Ben Earl and Luke Morahan put Bristol 28-0 up in as many minutes before Alex Dombrandt replied on the stroke of half-time.
Tyrone Green, James Chisholm and Louis Lynagh scores quickly cut the gap to 28-24 and Joe Marchant's late try sent the game into extra time at 31-31.
Green and Marchant tries either side of Malins' third sealed a remarkable win.
Quins will play Exeter in the final, with the defending champions seeing off Sale 40-30 in Saturday's second semi-final.
Bristol had topped the table from round six to the end of the regular season and looked on course for their first-ever Premiership final as they led 28-0 after 38 minutes.
However, the biggest-ever comeback in Premiership history - surpassing Harlequins' own from 40-13 down to beat Wasps 42-40 in September 2012 - earned the Londoners a 'home' final at Twickenham next Saturday where they will face either Exeter or Sale.
Roared on by most of the 6,000 supporters at Ashton Gate, Bristol started at a furious tempo, bamboozling Quins with pace and power, and after two early Callum Sheedy penalties, Earl and Malin went over in the corner to make it 16-0 in just 12 minutes.