Media playback is not supported on this device
The win and results in France mean Cardiff Blues go to Stade Francais for a European Champions Cup semi-final play-off on 19 or 20 May.
At Caerphilly the hosts' Carl Meyer scored off Angus O'Brien's cross-kick.
But Blues hit back with tries by Matthew Morgan and Willis Halaholo before Dragons' Sam Beard went over.
Gareth Anscombe kicked the rest of Blues' points with O'Brien and Meyer adding Dragons' extras.
The hosts' off-loading and wide passes caught Blues cold in the opening minutes.
Dragons were rewarded as O'Brien spotted Meyer wide on the right and his pinpoint kick allowed the full-back to gather and score.
O'Brien failed with the conversion from wide out, but his first penalty put Dragons further ahead.
However, at the other end the Dragons' fly-half fluffed gathering Matthew Morgan's kick ahead and the Blues full-back took his chance in style with Anscombe converting.
Another O'Brien penalty put Dragons back in front, but Halaholo bamboozled the home defence with his footwork to go over.
Anscombe added the conversion to give his side a 14-11 lead at the break.
The Wales international rewarded more Blues pressure with a penalty.
Worse could have come for the hosts as hooker T Rhys Thomas' neck roll on opposite number Matthew Rees earned the hooker 10 minutes in the sin bin.
But Blues could not capitalise and it was Meyer's long-range kicking that gave Dragons hope as he hit the target twice.
Anscombe kicked two more penalties in reply only for centre Beard to set up a late drama with an 80th-minute touchdown.
O'Brien added the conversion, but Blues held out to ensure victory.
Treviso's 19-3 win at Zebre allowed them to finish 10th to claim ninth spot and in the process claim Italy's automatic spot in the 2017-18 Champions Cup.
Dragons:  Carl Meyer, Adam Hughes, Tyler Morgan, Sam Beard, Pat Howard, Angus O'Brien, Charlie Davies; Sam Hobbs, Thomas Rhys Thomas, Brok Harris, Matthew Screech, Cory Hill, Lewis Evans (capt), Nic Cudd, Ollie Griffiths.
Replacements: Ellis Shipp, Phil Price, Craig Mitchell, Rynard Landman, Harrison Keddie, Sarel Pretorius, Geraint Rhys Jones, Jack Dixon.
Blues: Matthew Morgan; Alex Cuthbert, Rey Lee-Lo, Willis Halaholo, Rhun Williams; Gareth Anscombe, Lloyd Williams; Corey Domachowski, Matthew Rees, Taufa'ao Filise, Jarrad Hoeata, Macauley Cook, Sion Bennett, Ellis Jenkins (capt), Nick Williams.
Replacements: Ethan Lewis, Anton Peikrishvili, Keiron Assiratti, Seb Davies, Kirby Myhill, Tomos Williams, Steve Shingler, Tom James.
Referee: Ian Davies (Wales).
Assistant referees: Rhys Thomas (Wales) Simon Rees (Wales).
TMO: Paul Adams (Wales).
Cardiff Blues took seventh place in the Pro12 as they ground out victory in an uninspiring encounter with Welsh strugglers Newport Gwent Dragons.