Aberdeen left it late before securing a superb first-leg win with goals from Jayden Stockley, Adam Rooney and new loan signing Wes Burns – just when it looked like they were going to endure a night of frustration.
Derek McInnes’ side suffered a shocking defeat in Luxembourg last week before creeping through against Fola Esch.
But they thoroughly deserved to take an advantage to Latvia next week, although they left it very late before stunning Ventspils.
Stockbridge came off the bench and netted just four minutes later. Rooney added another, then new loan signing Burns netted in injury time with his first touch
But Aberdeen defender Ash Taylor was very lucky to avoid a red card after a very poor lunge in the second half.
Kenny McLean nearly settled any early Dons nerves in the third minute when Jonny Hayes clipped in a dangerous cross from the left and the ex-St Mirren midfielder stretched his neck muscles and was just too high with the header.
But the visitors were also proving a threat and Nikita Kojesovs should have done better than tamely shoot wide at the back post after a deep corner eluded the Dons defence. The home side eventually started to turn the screw as the interval approached and a low cross from Hayes was only just behind the onrushing Rooney and he could only angle the ball wide after a quick home attack.
Aberdeen came even closer to making the breakthrough five minutes before half-time when Niall McGinn teed up Graeme Shinnie. The midfielder’s blast was saved by Maksims Uvarenko, but it was too hot to hold and the ball spun towards goal before it was booted clear in the nick of time.
McGinn was thwarted by a superb flying save from the Latvian keeper after he curled a free kick around the wall and Shay Logan was then denied by a desperate block as Aberdeen turned up the heat after the interval.
But the increasingly erratic Taylor was very lucky not to be dismissed when he overran the ball and went for an awful lunge on Alexsei Alekseev. Despite strong Latvian protests, Portuguese ref Joao Pinheiro only flashed a yellow.
Taylor could have added salt into the wounds by netting from a McGinn corner, but he nodded it over.
But the Scots finally made the breakthrough in the 72nd minute when sub Stockley, who had only been on for four minutes when he replaced Kenny McLean, powered in a header at the back post from a pinpoint Hayes cross.
And the Dons doubled their advantage four minutes later when a McGinn corner wasn’t cleared, Stockley caused havoc with a sliced shot and Rooney was at the right place at the right time to bury it.
The icing on the cake was when Bristol City loan striker Burns came on and netted with a header from a McGinn corner to surely end the tie.