Dundalk's dreams of the Champions League group stages were left hanging by a thread after a fortunate penalty award set Legia Warsaw on the way to a 2-0 victory in Dublin.
Hungarian striker Nemanja Nikolic's spot-kick broke the Lilywhites' brave resistance in the 55th minute and a second from substitute Aleksandar Prijovic, only seconds from the final whistle, surely ended their hopes of progression.
Andy Boyle was unlucky to give away the crucial penalty when a drive from Legia winger Steeven Langil flashed past the defender's onrushing frame and cannoned into his trailing right arm.
Nikolic made no mistake from 12 yards, sending Gary Rogers the wrong way as he slotted the ball low into the left corner.
A sustained period of Legia pressure followed the goal, but Stephen Kenny's Dundalk players held firm.
However, as the final whistle approached, they were punished for pushing for an equaliser as Prijovic broke free to lift the ball over the oncoming Rogers and send the Polish champions to the brink of the group stages.
Dundalk, who face a massive task in the return leg in Poland next week, had actually started the game the brighter, keeping the ball well on a surface slicked by the evening downpour.
Patrick McEleney went close early on, running from deep to head over a well-placed cross from John Mountney.
Soon afterwards the forward had another chance, rasping a shot from distance high and wide.
In front of over 30,000 fans at the Aviva Stadium, Daryl Horgan made some inroads on the left wing.
But as the first half wore on the hosts became guilty of overplaying, giving the ball away too often in their own territory.
Captain Stephen O'Donnell picked up a yellow card after bringing down Vadis Odjidja as the midfielder charged into the box. Rogers was untroubled by the resultant free-kick, which rattled into the wall.
The keeper was called into action two minutes later when he was forced the claw away a goal-bound cross-cum-shot from Langil.
Legia maintained the pressure and Michal Kucharczyk came close with a powerful half-volley that flashed past Rogers' left upright.
As half-time approached Dundalk seized back the initiative and created some chances of their own.
The League of Ireland champions came close to breaking the deadlock when Horgan burst into the box in pursuit of a deft flick from the impressive McEleney.
A Legia defender nicked the ball away from Horgan's right foot just before he pulled the trigger.
At the start of the second half Dundalk midfielder Chris Shields was at the heart of two half-chances in as many minutes.
First he stretched well to meet a deep cross, but his header did not have the power to trouble keeper Arkadiusz Malarz. Then he made a powerful run to set up Horgan for a low drive straight at Malarz.
But the penalty injected fresh confidence into the visitors and Dundalk were forced further and further back.
Roared on by their small but vocal travelling support, Legia fashioned a series of chances in quick succession, with Kucharczyk coming close to doubling their lead on a number of occasions.
Langil also threatened again with a drilled shot from distance that just cleared the bar.
With two minutes left the hosts came close to levelling the tie when substitute Ciaran Kilduff struck a half-chance over the top.
But in the end, the second, and surely crucial, goal was grabbed by Legia.
ends
UEFA Champions League News
Liverpool's Champions League clash with Leipzig returns to Budapest
Liverpool will return to Budapest to play RB Leipzig in the their Champions League round-of-16 second leg match due to COVID-19 travel restrictions.
Should Atletico be worried Simeone is following Wenger's path ahead of Madrid test?
Do Atletico Madrid's failures in big games suggest Diego Simeone is following a Wenger-style decline by losing his edge and becoming "comfortable?"
Man City's Guardiola warns players they could be axed if they think title is won
Manchester City manager Pep Guardiola has warned his players that anyone believing the Premier League title is already won will be axed.
Does Joao Felix need to leave Atleti to fulfill his potential?
ESPN FC's Don Hutchison on how Joao Felix's potential is hampered at Atletico Madrid.
Champions League talking points: Do you take Mbappe or Haaland? Will Messi and Ronaldo win it again?
The first legs of the Champions League round of 16 featured plenty of things to discuss; Gab Marcotti, Mark Ogden and Graham Hunter have their say.
Atalanta's Gian Piero Gasperini slams referee who 'ruined' match against Real Madrid
Gian Piero Gasperini said the referee ruined the match by sending off Remo Freuler early on in Atalanta' 1-0 UCL defeat to Real Madrid on Wednesday.