"This is the longest season that I've ever had and we're here at worlds, so it's a good experience for me," said the 17-year-old Chen, who previously had complained of problems with his skate boots. "Whatever happened, happened, and I just have to put it behind me."
Sixth place for Chen and seventh for Jason Brown meant that the U.S. joined Japan as the only two countries to earn the maximum three spots in the men's event at next year's Pyeongchang Olympics.
Short program leader Javier Fernandez of Spain, skating last, dropped to fourth with a fall and other errors, giving Hanyu his second career world title after victory in 2014.
The 22-year-old Hanyu, who was in tears of joy after learning his score, praised the passionate support from Japanese fans.
"After the short program, I was quite depressed. I was so deeply depressed," he said. "But the fans and the team believed in me."
Still, Hanyu suggested his struggles in Thursday's short program could foreshadow problems for his hopes of winning a second Olympic gold.
"I still feel it's very difficult to put out two clean programs," he said. "Toward the Olympic season, I think it's important to skate clean both in the short and the free, these two programs together."
The silver went to Japan's Shoma Uno with a 319.31-point total on a strong day for figure skating in Japan, which has won six of the 12 world championships men's medals awarded over the last four seasons.
China's Jin Boyang was the bronze medalist for the second straight year, scoring 303.58.
"I just want to focus on my program and make it perfect, and I did it today," he said. "Whether I got a medal or not, I was quite happy."
Three-time world champion Patrick Chan was fifth behind fellow veteran Fernandez.
Saturday's free skate illustrated the relentless march in men's figure skating toward ever more quad jumps, which demand huge power and control from a skater.
The final six skaters to take the ice Saturday attempted 24 high-risk quad jumps between them, with three falls two of them for Chen and a few more awkward landings.