Lincoln Red Imps 1-1 The New Saints
Dean Ebbe's late goal saw The New Saints progress to the third qualifying round of the Europa League.
The Welsh champions travelled to Gibraltar having beaten Lincoln Red Imps 2-1 in the home leg.
Juan Manuel Montesinos Romero took advantage of a defensive mix-up to put the home side ahead in the second leg.
But Ebbe restored the Saints' advantage on aggregate just after the 80-minute mark, meaning Scott Ruscoe's side will now face Midtjylland of Denmark.
They will play the home leg of the tie at Cardiff City Stadium on Thursday, 9 August.
Ruscoe told BBC Sport Wales his side made "hard work" of Thursday's game.
"We weren't great tonight, we weren't at our best but we're through to the next round which is the important factor.
"3-2 overall is a decent score line really... There's nothing like going to another country to play and getting victories.
"At the end of the day we'll celebrate the victory, not the performance."
Lincoln Red Imps
- 1Soler Ortuño
- 15dos Santos
- 99Ortiz JiménezSubstituted forCalderón Vallejoat 75'minutes
- 20GarroSubstituted forCorral Valeroat 45'minutes
- 28Gámiz Maroto
- 21Montesinos RomeroSubstituted forSergeantat 81'minutes
- 18Corral Valero
- 19Calderón Vallejo
- 10RedmondSubstituted forCieslewiczat 68'minutes
- 4HollandBooked at 78minsSubstituted forDraperat 79'minutes
- 12HudsonBooked at 90mins
- 22LewisBooked at 89mins
- 21ByrneSubstituted forEbbeat 45'minutes
- Petri Viljanen