Adisak Kraisorn was Thailand's hero as the War Elephants drew 2-2 with Iraq in Tehran on Thursday night to move into the final stage of AFC qualifying for the 2018 World Cup in Russia.
At the same time, Thailand secured a place in the 2019 Asian Cup as the country celebrated arguably its greatest football achievement of all time.
After a difficult start, Kiatisuk Senamuang's men took a first half lead through Mongkol Tossakrai's excellent header. Iraq levelled through Mahdi Kamil midway through the second period before Adisak struck with five minutes remaining to send the visiting Thai fans wild. Ali Adnan struck a second equaliser with the final kick of the game in injury time but it was too little, too late as Thailand sealed top spot in Group F.
It is the first time that Thailand have reached the final stage of AFC World Cup qualifying since the campaign for the 2002 finals, and only the second occasion in their history.
The War Elephants almost got off to the worst possible start when a sweeping ball caught Theerathon Bunmathan wrong side of Younis Mahmoud inside the penalty box. The two collided, with the Iraqi claiming a penalty, which would also have led to a red card. The Thais breathed a sigh of relief as the Qatari referee waved played on.
There was another let-off minutes later when Iraq had a goal disallowed for offside after more slack defending.
When the Thais created their first opening after 12 minutes, midfielder Pokklaw Anan wastefully shot over from distance when there was space to move into.
A minute later, Mongkol won a free-kick on the corner of the Iraqi 18-yard box. Theerathon's free-kick was as wasteful as Pokklaw's effort but at least Thailand were starting to create after a torrid opening.
It seemed a false dawn when Tanaboon Kesarat horribly mistimed his jump after a long throw but Mohannad Abdul-Raheem failed to take advantage as his close-range effort went wide.
Goalkeeper Kawin Thamsatchanan then came to the rescue when a long ball was nodded down by Mahmoud into the path of Saad Abdulamir. The striker fired a stinging drive from 20 yards but Kawin dived acrobatically to divert the ball wide.
Chanathip 'Messi J' Songkrasin made his mark for the first time in the game after 28 minutes when he broke clear on the left but his shot from an angle brought a comfortable save from Noor Sabri.
Kawin was at his acrobatic best again when, at full stretch, he held Mahmoud's header from 18 yards out.
And the Thais stunned most of the Tehran crowd when they took the lead in the 39th minute. Iraq conceded a corner after a scrambled clearance and, from Theerathon's kick, Army United winger Mongkol leapt superbly to nod home from an angle.
As half-time approached, Dhurgham Ismael shot over from a good opening on the left and Abdul-Raheem's furious reaction was evidence of the home side's growing frustration.
Iraq inevitably hit back in the second half. There was a scare for the War Elephants when Salam Shaker's speculative lob from the edge of the box almost caught out Kawin, who collided with the post as he caught the ball. Minutes later, a menacing run by Hosni Faisal on the left ended with a dangerous cut-back that fortuitously evaded the Iraqi attack.
Kiatisuk made what seemed an attacking substitution in the 63rd minute as goal scoring winger Mongkol was replaced by attacker Adisak.
Iraq then replaced national team legend Mahmoud with Hammadi Ahmed.
And Yahya Alwan's side found the equaliser in the 65th minute. Faisal again found space on the left and fired in a powerful shot. Kawin could only push the effort into the path of Kamil, who tapped into an empty net.
If Kawin had been slightly at fault for the goal, he redeemed himself a minute later when he made an excellent save from Shaker's powerful header as the Thais reeled from the blow of the leveller.
Kiatsuk signalled his intentions as he withdrew playmaker Chanathip for Suphanburi central defender Pratum Chutong with 15 minutes remaining.
The Thais were having to dig deep to keep out the Iraqis but came close to regaining the lead when the ball broke to Teerasil Dangda just outside the box. The Muang Thong United striker hit a powerful left-footed shot just wide of the post.
Adnan and Hosni then combined to threaten the Thai defence again but Ahmed failed to find a finishing touch from a good position as the game reached its closing stages.
Incredibly, Thailand retook the lead through Adisak with just five minutes remaining. After winning a free kick on the right, Theerathon's wicked delivery found the Muang Thong man at the far post and he escaped the attentions of Faisal Jassim to slot home from close range.
Iraq tried in vain to get back into the game until Adnan struck in the game's final attack.
Thailand were left to celebrate possibly the greatest result in their history and can look forward to more exciting World Cup action.