The temple was first founded in 1367, by a Japanese monk from Satsuma province by the name of Raijū and with the patronage of the royal government of Chūzan, as a companion to the Naminoue Shrine already located on the bluff, overlooking the beach and ocean.
Centuries later, in 1846, the temple was taken over by the doctor and Christian missionary Bernard Jean Bettelheim, who occupied it for seven years, driving off Buddhist worshipers and the temple's rightful occupants. Working as a lay medical missionary under the auspices of the Loochoo Naval Mission, when Bettelheim's ship, HMS Starling, arrived at Naha, the Okinawan port master protested that he should not be allowed to disembark. HMS Starling's captain wished to honor this request, but Bettelheim made his way ashore anyway and ended up being offered shelter in the Gokoku-ji for that night; he would not leave for seven years. Turning away worshipers and monks alike by suggesting that they were trying to observe his wife, Bettelheim boarded up the temple's sanctuary and threw out much of what he called "the heathen furniture of idolatry". The Ryukyuan royal government soon deemed it necessary to keep an eye on Bettelheim, who had become more than a nuisance, and a serious burden upon the local community. A guard post was erected just outside the temple grounds, and a detachment of men was assigned to both watch over the temple and to accompany the missionary as he traveled about the area.
When the American Commodore Matthew Perry arrived in 1853, Bettelheim served for a time as translator and intermediary. Over the missionary's objections, the Commodore established an American base within the grounds of the Gokoku-ji, including a fenced-off area for grazing cattle, something which drew strong protest from the Ryukyuan authorities. When Perry departed from his second visit to Okinawa a year later, he was offered, among other gifts from the Kingdom to the United States, a temple bell from Shuri. This was found to be imperfect, so a bell from the Gokoku-ji was offered instead. This bell had been forged in 1456, during the reign of Shō Taikyū. The inscription upon it reads in part "May the sound of this bell shatter illusory dreams, perfect the souls of mankind, and enable the King and his subjects to live so virtuously that barbarians will find no occasion to invade the Kingdom." It being part of the Bettelheim residence, which had been desecrated and not used as a place of worship for roughly eight years, the Ryukyuan authorities were willing to part with it; Bettelheim likewise expressed in his diary elation at seeing the heathen temple further dismantled. Intended by Perry to be installed in or near the Washington Monument then under construction, the associated committee turned down the suggestion, and the bell was instead donated to the U.S. Naval Academy at Annapolis, where it was kept and rung in celebration of Navy victories in the annual Army–Navy football game, until it was finally returned to Japan in 1987. Bettelheim left Okinawa with Perry, restoring the temple to its proper occupants and purpose. In 1871, a Ryukyuan ship was blown off course by a storm and landed on Taiwan where, following a conflict with local Paiwan aborigines, a number of Okinawans were killed. This became an international incident as Japan and China disagreed over the sovereignty of both Okinawa and Taiwan, and thus over whether China owed any form of restitution to Japan. The remains of the Okinawans killed were said to have been recovered and were buried at the Gokoku-ji, a grand ritual performed for them, who were said to have died in the service of the State. Destroyed in the 1945 battle of Okinawa, the temple was rebuilt shortly afterwards and remains operational today. A stone erected in 1926 as a memorial to Dr. Bettelheim also remains or has been reconstructed.