Kokuji temple was founded in 1227 by Gansho shonin to assure the repose of the soul of Minamoto no Sanetomo, the third Kamakura Shogun. Originally the temple was called Shohoji temple and belonged to the Shingon sect of Buddhism. In 1258 Gansho Shonin invited Kakushin to become the temple’s head priest. Kakushin changed the temple’s sect from the Shingo to Rinzai sect of Zen. Kakushin died in 1298 and was given the honorable title “Kokushi”after his death. In 1340 Emperor Gomurakami honored the temple itself with the new name of “Kokokuji”. In 1585 Hashiba Hideyoshi’s army attacked Kishu (now Wakayama), burning the most of Kokokuji’s buildings to the ground. Later, under the patronage of the Daimyo (feudal lord) of the Asano and the Tokugawa, the buildings were reconstructed.
The temple is also the place of origin of Kinzanji miso, a fermented food made from soybeans, which is the origin of soy sauce.
It is noted that Kokokuji is the birthplace of the custom among Zen Buddhists of wearing bamboo baskets over their heads and playing shakuhachi, a long vertical flute.
There is a legend that Tengu rebuilt the buildings of Kokokuji temple in one night after a big fire.