Co-hosts Austria were given a Euro 2008 lifeline when Ivica Vastic scored a stoppage-time penalty against Poland.
English referee Howard Webb ruled that Mariusz Lewandowski hauled down Sebastian Proedl and substitute Vastic slammed the penalty past Artur Boruc.
Boruc had earlier made a string of stunning saves to deny Austria, with Martin Harnik wasting two fine chances.
Poland's goal came when Roger Guerreiro converted a first-half cross from an offside position three yards out.
It was a dramatic end in Vienna and both sides' chances of qualifying for the quarter-finals remain slim, though Vastic's goal does send Croatia through to the last eight.
Austria probably deserved a point for their dominance in the first half an hour, but until Webb pointed to the spot two minutes into injury time it looked as though their chance had gone.
In truth, the game should have already been dead and buried in the Austrians' favour.
The home side made a sensational start to the game and they could - and should - have been 3-0 up with only 15 minutes on the clock.
First Harnik took advantage of Mariusz Jop's hesitancy to surge through on goal only to see Boruc deflect his shot inches wide of the target.
Moments later, Unit Korkmaz used his explosive pace to waltz past two men down the left and cross for Harnik, eight yards out, to shoot straight at Boruc.
When Poland's flimsy offside trap was breached once more for Christoph Leitgeb to run in unchallenged on goal it seemed as though Austria had to score, but again the heroic Boruc spread himself and the shot cannoned into his midriff.
Roger's first-half goal was not enough to earn Poland victory
Having been so profligate, Austria were punished in devastating fashion by the Poles on the half-hour mark.
Ebi Smolarek crossed to the far side of the penalty box from the left wing, Marek Saganowski turned inside Emanuel Pogatetz and his cross-shot was poked home by Roger from close range.
It was doubly harsh on the Austrians because Roger was clearly standing in an offside position when the ball left Southampton striker Saganowski's foot.
Poland took Jop off at half-time and within seconds of the restart his replacement Pawel Golanski was a little lucky not to concede a penalty, as the defender's hands were all over Andreas Ivanschitz with the Austrian captain moving in on goal.
But the Poles had largely sorted out their defensive problems from the first half and were enjoying more possession, with the skilful Roger central to their attacking ambitions.
He floated over a cross from the right that Jacek Bak chested down and fired in, Jurgen Macho making an impressive save with his right leg to keep Austria in it.
Macho produced more heroics when he arched his back to tip over Jacek Krzynowek's sizzling 35-yard left-foot free-kick but the co-hosts, weary and still reeling from Roger's sucker-punch, were hanging on.
But with the clock running down and Austria's chances hanging by a thread, Webb stunned the Poles by pointing to the spot and 38-year-old Vastic rifled in to become the oldest scorer in European Championship history.
Austria: Macho, Garics, Prodl, Stranzl, Pogatetz, Leitgeb, Aufhauser (Saumel 74), Ivanschitz (Vastic 64), Korkmaz, Harnik, Linz (Kienast 64).
Subs Not Used: Manninger, Ozcan, Standfest, Fuchs, Gercaliu, Katzer, Patocka, Hiden, Hoffer.
Booked: Korkmaz, Prodl.
Goals: Vastic 90 pen.
Poland: Boruc, Wasilewski, Jop (Golanski 46), Bak, Zewlakow, Dudka, Lewandowski, Krzynowek, Roger (Murawski 85), Saganowski (Lobodzinski 83), Smolarek.
Subs Not Used: Kowalewski, Fabianski, Wawrzyniak, Gargula, Pazdan, Zahorski, Kokoszka.
Booked: Wasilewski, Krzynowek, Bak.
Goals: Roger 30.
Ref: Howard Webb (England).