Shoichi Yokoi, a Japanese soldier who hid in the jungles of Guam for 27 years rather than surrender to American forces at the end of World War II, died on Monday of a heart attack. He was 82.

Mr. Yokoi returned in 1972 to Japan -- an entirely different country than the one he had last seen in August 1940 -- and he stirred widespread soul-searching within Japan about whether he represented the best impulses of the national spirit or the silliest.

''I am ashamed that I have returned alive,'' Mr. Yokoi declared after his return, reflecting the traditional warrior spirit that it is better to die than to give oneself up to the enemy.

''Your Majesties, I have returned home,'' Mr. Yokoi said during a visit to the grounds of the Imperial Palace, where the Emperor and Empress live. ''I deeply regret that I could not serve you well. The world has certainly changed, but my determination to serve you will never change.''