This picture taken on March 11, 1974 shows former Japanese imperial army soldier Hiroo Onoda (R) offering his military sword to former Philippine President Ferdinand Marcos to express his surrender. (JIJI PRESS/AFP/Getty Images)

The formal surrender of Japan was held in Tokyo Bay on Sept. 2, 1945 — weeks after two atomic bomb blasts brought an end to years of carnage. Emperor Hirohito called on the Japanese to “endure the unendurable,” forfeiting the cause that led millions of his countrymen to their graves.

World War II was over — but not for Hiroo Onoda. A lieutenant in the Imperial Japanese Army, Mr. Onoda spent an additional 29 years hiding in the jungle of an isolated Philippine island.

The Japanese government spent a small fortune trying to alert stragglers like Mr. Onoda about the war’s end, but he dismissed it as enemy propaganda. He stuck to his gun and headed back into the bush in the service of his emperor, bracing for an enemy that didn’t exist anymore.

For Mr. Onoda, who continued beyond belief to follow wartime orders, loyalty was not only blind but deaf.

He emerged in 1974, emaciated but still sporting what remained of his old uniform. Mr. Onoda, who died Jan. 16 at age 91, was the last Japanese soldier to come out of hiding in the Philippines, having survived through thievery, ­asceticism and undeviating will. He said he thought of “nothing but accomplishing my duty.”

To many Japanese at the time, he embodied prewar virtues of endurance, obedience and sacrifice — qualities that seemed increasingly antiquated as the country transformed from the devastation of war into an economic powerhouse and a hive of materialism.

At the time of Mr. Onoda’s surrender, the Japanese ambassador to the Philippines declared him the “paragon of the Japanese soldier.”

Other Japanese soldiers from World War II lived on for decades, guerrilla-style recluses in the jungles of Guam and Indonesia, but Mr. Onoda stirred the deepest emotional and nostalgic response. Many who stayed hidden for so long cited fear of execution, but Mr. Onoda remained committed to his mission of watching the skies for American bombers.

His orders: “To continue carrying out your mission even after the Japanese Army surrenders, no matter what happens.”

The cost was extreme. When he left the jungle at long last, he met a world where Richard M. Nixon was the U.S. president, where the Cold War and the nuclear age dominated politics, where skyscrapers towered, where television was inescapable. (He did not marvel at the small-screen technology, saying that it “irritates my eyes.”)

If he seemed lost in the new world, some circumstances of his youth seemed to have remained the same. He said he was restless when he returned at last to his home region in central Japan and settled in with his octogenarian parents, who had long believed him dead. He did not get along with them when he was a teenager, and time had not changed a thing, he said. He soon returned to isolation, this time as a rancher in Brazil.

A teacher’s son, Hiroo Onoda was born March 19, 1922, in Kai­nan, Japan. He completed high school in 1939 and worked for a Japanese trading firm before he was drafted into the army.

The Japanese invasion of the Philippines began shortly after the Dec. 7, 1941, attack on Pearl Harbor, and the islands’ occupation for the next several years led to atrocities that included the Bataan Death March. Mr. Onoda, a graduate of the imperial army’s intelligence school, was assigned to Lubang, an island about 90 miles southwest of Manila, in December 1944.

Just two months earlier, U.S. Gen. Douglas MacArthur had begun retaking the Philippines, starting with Leyte island. By March 1945, Manila was officially liberated, although scattered resistance continued until the war’s end.

Mr. Onoda and a few other soldiers went underground, waging a low-level guerrilla campaign while still in their old fatigues. One of the men surrendered a few years after the war. Others were killed in gun battles with the Philippine police — the last in 1972 — reinforcing Mr. Onoda’s belief, he said, that the war was still on.

As the decades passed, Mr. Ono­da’s family made attempts, via loudspeaker and dropped leaflets, to persuade him to come out of hiding. He later professed to disbelieve the war was truly over: The blandishments to leave his post must be Allied propaganda.

But he got older and a life of banditry became more difficult. He seemed more amenable to reality when he crossed paths in February 1974 with a young Japanese adventurer, Norio Suzuki, who had gone in quixotic pursuit of Mr. Onoda.

As farfetched as his nearly 30 years in isolation seemed, Mr. Onoda explained his perspective to Suzuki: If the war were truly over, why had he never received orders from his superiors?

Suzuki took this message back to Japan, where the military located Mr. Onoda’s superior officer, former Maj. Yoshimi Taniguchi, who had gone on to a career as a bookseller, and arranged for his transport to Lubang.

Mr. Onoda stood at attention with his regulation army rifle as Taniguchi read out the imperial army’s proclamation of surrender from 1945.

As Time magazine reported of the “wartime Rip van Winkle,” Mr. Onoda “bowed stiffly in acknowledgment that his war was over — and then proceeded to brief his commander about his 29 years of intelligence gathered on ‘enemy movements.’ ”

Soon after, in Manila, the 52-year-old Mr. Onoda formally surrendered to Philippine President Ferdinand Marcos. Mr. Onoda presented his rusted samurai sword, and Marcos returned it after pardoning the old soldier for crimes he may have committed. Mr. Onoda and the men with him admitted to stealing rice, bananas and cattle, and they were suspected of killing and wounding Filipinos who came upon the fugitive soldiers at various times.

Mr. Onoda’s story became a sensation. He received a hero’s welcome in Japan, where politicians have long paid tribute to nationalistic and militaristic traditions even as the country’s post-World War II constitution renounced war forever.

Thousands of onlookers welcomed him back to Tokyo. The Japanese prime minister, Kakuei Tanaka, wrote a celebratory message in Mr. Onoda’s honor: “The air of a heavenly hero will prove awesome through a thousand autumns.”

He was also feted in dubious corners of the world. The Ugandan dictator Idi Amin said Mr. Onoda’s dedication to a cause would make him an ideal morale-builder for Uganda’s army.

Mr. Onoda decamped for a ranching enclave in the Brazilian interior populated by dozens of Japanese families. In 1976, he married Machie Onuki, 38, a former tea-ceremony hostess from Tokyo.

They later led a school in northern Japan that taught wilderness survival skills to youngsters, who called Mr. Onoda ­“Uncle Jungle.”

He died at a hospital in Tokyo, the government announced. No cause was reported.

Mr. Onoda, whose ghostwritten memoir was called “No Surrender,” bemoaned what he called a lack of self-reliance among contemporary Japanese.

He once told Reuters that he advised parents to let their children play in the soil and dirt, even when it was raining.

“Too much concrete and cleanliness makes for weak children,” he said.