The last Japanese soldier to come out of hiding and surrender, almost 30 years after the end of the second world war, has died.

Hiroo Onoda, an army intelligence officer, caused a sensation when he was persuaded to come out of hiding in the Philippine jungle in 1974.

The native of Wakayama prefecture in western Japan died of heart failure at a hospital in Tokyo on Thursday, his family said. He was 91.

Onoda’s three decades spent in the jungle – initially with three comrades and finally alone – came to be seen as an example of the extraordinary lengths to which some Japanese soldiers would go to demonstrate their loyalty to the then emperor, in whose name they fought.

Refusing to believe that the war had ended with Japan’s defeat in August 1945, Onoda drew on his training in guerilla warfare to kill as many as 30 people whom he mistakenly believed to be enemy soldiers.

The world had known of his existence since 1950 when one of his fellow stragglers emerged and returned to Japan. A second member of the group reportedly died in 1950.

Onoda, whose sole remaining companion was killed in a shootout with Philippine troops in 1972, held firm until two years later.

He was only persuaded to surrender when his former commanding officer travelled to his hideout on the island of Lubang in the north-western Philippines and convinced him that the war had ended.

Until then, Onoda would later explain, he believed attempts to persuade him to leave were a plot concocted by the pro-US government in Tokyo. By the time he surrendered he had been on the island since 1944, two years after he was drafted into the Japanese imperial army.

Onoda wept uncontrollably as he agreed to lay down his perfectly serviceable rifle.

He was later pardoned for the killings by the then Philippine president, Ferdinand Marcos. In his formal surrender to Marcos, Onoda wore his 30-year-old imperial army uniform, cap and sword, all of which were in good condition.

He returned to Japan in March the same year, but after struggling to adapt to life in his homeland, he emigrated to Brazil in 1975 to become a farmer. He returned to Japan in 1984 and opened nature camps for children across Japan.

Japan’s top government spokesman, Yoshihide Suga, praised Onoda’s strong will to live, telling reporters on Friday: "I vividly remember that I was reassured of the end of the war when Mr Onoda returned to Japan."

Onoda was one of several Japanese soldiers who remained holed up in their former battlegrounds long after the war ended.

Onoda, like Shoichi Yokoi, a soldier who was found on the island of Guam in 1972, dismissed reports declaring the war’s end as Allied propaganda. On his return to a hero’s welcome in Japan, Yokoi famously

said: “It is with much embarrassment, but I have returned.”

In 2005 there were unsubstantiated claims that two former Japanese soldiers in their 80s were still in hiding in the mountains on the Philippine island of Mindanao. The men were reportedly afraid that they would be court-martialled for desertion if they gave themselves up.