China's Xu won 11-6, 5-11, 11-13, 11-7, 12-10, 11-8 to take gold, but he was pushed hard by the Chinese world number two and youth Olympics champion.
"The final was very tough, both Fan Zhendong and I played at the highest level," Xu said.
Xu drew away easily to win the first game 11-6 and it seemed that Fan might be suffering from stage fright in his first Asian Games against a man he had called a "superstar" earlier in the week.
However Fan blasted back with a runaway 11-5 to level and from then on a ding-dong, ping-pong classic unfolded.
They were locked 11-11 in the third when Fan unleashed a magical backhand to go to game point and converted as Xu, who had held game point at 10-9, went long.
"I think the most important factor was my mental toughness on the crucial points," said Xu.
"In the third, I threw away a game point but I was able to bounce back quickly in the fourth. I think that was the key to the victory."
Xu blitzed through the fourth and turned the match by saving game points in the fifth before winning it 12-10.
From 4-4 in the sixth, Xu put in a run of five points in a row to stand just two away from gold. But again the young Fan blew back to 9-8.
Xu used all his experience force the teenager into two mistakes to close out the match and then fell on to his back in relief.
Xu was full of praise for his young opponent. "It's remarkable that he's only 17 but is able to achieve so much," he told AFP.
In another all-China final fleet-footed Liu Shiwen swept aside Zhu Yuling 4-0 (11-6, 11-4, 13-11, 11-7) to take the women's singles gold.
Liu was troubled only once, in the third game, when Zhu held a game point at 10-9, but she saved it with a lightning quick backhand and came through 13-11.
"I'm very excited to have won the title," she said. "I never dreamt I would win 4-0. During the match I just kept telling myself to stay focused and fight for every point."
The two golds took China to 151 for the Asian Games.