He was down 3-5 in the final set an again 1-4 in the tie-break. The Thai even had to suppress his left knee injury at 7-6 in the mini-set which urged him to call for an on-court treatment.
But after An hit a forehand long in the next point, the crowd was in jubilant to see him finish the victor with a 3-6, 6-1, 7-6 (8-6) score line after almost three hours of nail-biting battle.
Danai, obviously hampered by the foot and knee injuries, looked slower than usual which allowed the South Korean to dominate the first four games. The Thai gritted his teeth to win a few games but a forehand error cost him the first set.
The top seed faced two break points in the first game of the second set but fought bravely to hold serves to restore his confidence. He went on to lead 2-1 and drew echoing roars from the entire stadium after wrong-footing An with a forehand winner to gain the upper-hand for the first time at 3-1.
Since then the situation became one-way traffic for Danai who reeled of three games in a row to wrap up the 38-minute second set.
In the decider, the South Korean called for a medical time-out for to have his injured back treated after he held the first game. As play resumed he was on fire, forcing Danai to make errors and built a 4-1 lead. Danai then took turn in request for a trainer because of the same problem.
An was serving for the match at 5-3 but at this crucial stage Danai threw his last dice into the match. He moved the young opponent from corner to corner and broke back to 4-5 after the South Korean dumped a forehand to the net.
Danai had his chance to close out the match too, serving at 6-5 but did not capitalize it. But he proved mentally tougher on crucial stage and eventually won the thriller.
Thailand has won two gold medals including the men's doubles by Sonchat and Sanchai Ratiwatana.
In the women's singles final, Alisa Kleybanova of Russia beat Estonia's Margit Ruutel 6-1 6-2.