Sayed Ahmed's fortunate cross-cum-shot gifted Bahrain a 2-1 victory in its AFC Asian Cup Group C dead rubber with Qatar in Sydney on Monday.
Both sides were left to play for pride in their final pool match at Stadium Australia after defeats to Iran and United Arab Emirates.
Bahrain midfielder Sayed Dhiya opened the scoring in an entertaining encounter with a well-taken, close-range finish 10 minutes before half-time.
Qatar had failed to take advantage of a number of opportunities earlier in the match, but Hassan Khalid Al Haidos looked to have sealed the point his team's play merited with a 68th-minute free-kick.
However, there was to be a final twist in the tale as a looping ball from Sayed Ahmed went over Qatar goalkeeper Qasem Burhan's head and into the net eight minutes from time.
Striker Mohammed Muntari spurned two clear chances to give Qatar the lead in the early going.
First, Muntari fired narrowly wide from a long ball over the top of the Bahrain defence and he then headed against the corner of the crossbar from a left-wing free-kick.
Bahrain did offer an attacking threat, though, and was unfortunate not to take the lead when Dhiya struck the base of the post with a diving header.
Forward Al Haidos had an effort cleared off the line as Qatar continued to pour forward but was caught by a sucker punch from Dhiya.
Dhiya converted from close range from Faouzi Aaish's pull-back after fine work down the left.
Muntari displayed further profligacy in front of goal at the other end by heading off target from a left-wing cross before Boualem Khoukhi was thwarted by a save with his face from Bahrain keeper Hamad Al Doseri.
Al Doseri came to the rescue again shortly after the interval as his fine one-on-one save kept Ali Assadalla from restoring parity.
Muntari finally put the ball in net only to be correctly flagged for offside, yet Al Haidos deservedly levelled matters with a low set-piece into the bottom right corner from the edge of the area.
Qatar saw chances to complete the turnaround wasted by Muntari, and it was punished as it exits the Asian Cup without a point to its name.