Marit Bouwmeester (NED) took silver and Evi Van Acker (BEL) claimed bronze in winds up to 14 knots on the Nothe course, close to a large crowd which cheered sailors around every mark.
Just one point had separated the top four Laser Radial sailors entering the medal race, with Xu and Bouwmeester level on 33 points each and Annalise Murphy (IRE) and Van Acker tied on 34.
Murphy led around the first mark, but Xu overtook her before being given the penalty turns by on-the-water umpires for illegal propulsion. Remarkably though, the Beijing 2008 bronze medallist Xu then regained the lead before the end of the second leg and was never challenged from then on.
"I just give it my all," Xu said immediately after racing. "I really enjoyed today's race. I gave it my best for my country China. So long as I kept calm and did my best the end result would not be bad. Everybody was nervous; it just depends on who has the best mental side.
"I am proud of the gold, especially as I'm in Britain, because Britain and European countries are good and I want to take this experience back to China so more can experience the beauty of sailing."
Bouwmeester finished second in the Medal Race to take silver and after dominating the class throughout the last two years she was less than impressed with second place, "The gold is always the main goal," said Bouwmeester. "If you ask me tomorrow I will be fine; today I'm a bit disappointed."
When it looked like bronze would go to Murphy, Van Acker stepped it up to come through in third to her the Irish girls fifth. Van Acker said, "I was feeling 'Yes, no, yes, no, yes, no'. Then I just decided it's going to be now or never and it had to be 'Yes'. So I looked behind and thought 'Where's the gust?' It was exciting."
For Murphy, finishing in fourth, it was a bitter pill to swallow after she won four races in a row at the start of the competiton. The Irish girl said, "Anything was going to happen, down to the last lap, and it didn't go my way. Looking back, it would have been better if I'd done something simpler in the downwinds." On finishing fourth she added, "It's definitely the hardest position to finish, but I'll have to get over it."
1. Lijia Xu (CHN) - 35pts
2. Marit Bouwmeester (NED) - 37pts
3. Evi Van Acker (BEL) - 40pts
4. Annalise Murphy (IRL) - 44pts
5. Alison Young (GBR) - 60pts
Follow all the action on the ISAF Olympic Live Blog which will bring competition updates and instant reactions to the action on the race course. Fans can check in and ask our media team questions to get the very latest information. The blog will start one hour before racing each and every day of the competition.