The 19-year-old, crowned global junior champion in Barcelona on July 13, won gold with an 84.58 metre throw, a personal best. He was the youngest winner of an Olympic javelin title.
Ukraine's Oleksandr Pyatnytsya won silver with a 84.51 effort and Antti Ruuskanen of Finland took bronze with 84.12.
Walcott had such low expectations in London that he said he was "surprised I even made the final".
"I just went out there to relax and enjoy it and it worked for me," said Walcott, whose second-round effort was good enough for gold.
"It means everything to me. I just train my hardest and try to enjoy every time I come out."
Norwegian Andreas Thorkildsen, bidding for a third successive Olympic gold, was only sixth.
Thorkildsen has struggled with injury and technical problems all season and registered just two throws in the final. His best of 82.63 was way short of the Olympic record of 90.57 that he set in Beijing.