TOKYO -- When Yasuhiro Nakasone was elected prime minister of Japan five years ago, he was widely viewed as a political accident, too openly self-assured for a nation that reveres modesty and unlikely to rule more than a year.

As he prepares to step down -- first as president of his Liberal Democratic Party this weekend and then as prime minister on Nov. 6 -- Nakasone, 69, has proved the experts wrong, ending his tenure as one of the most domestically popular and internationally respected Japanese leaders of the postwar era.

He still is not beloved by his party's politicians, but he is given grudging respect, both for having held on to his post longer than any other prime minister in the past 15 years and for having forced some changes on a consensus-bound society and government that usually alter course only glacially.

"He's an unusual type of leader for Japan who has finally brought Japan onto the world stage, front and center," U.S. Ambassador Mike Mansfield said recently.

In five years, Nakasone edged Japan toward a larger international role commensurate with its greater wealth, forged a closer military alliance with the West and began to reshape Japan's economy and society to make it less dependent on exports and more in tune with the outside world.

Nakasone had his share of failures, too -- from an ill-fated effort to force the Japanese Diet, or parliament, to overhaul the tax code to growing trade tensions with the United States. And many opinion makers here continue to see Nakasone as a showboat who accomplished far less than he promised.

But, as one Diet member who belongs to Nakasone's party but does not particularly like the prime minister said recently, "starting from his fragile base, what he has accomplished is incredible."

In any case, Nakasone's "show" and his transformation of the image of Japan's top leader -- and, thus, of Japan itself -- mattered more to many here than any tally of policy wins and losses. Public opinion polls reveal a sense of pride among Japanese in an assertive leader who, for the first time, did not hang back in the shadows in international summits.

That Nakasone's clout is still waxing even as his term draws to a close was evident during the recent campaign to replace him. The three contestants, including the eventual victor, former finance minister Noboru Takeshita, felt compelled to swear allegiance to Nakasone's policies -- and eventually turned to him to end their competition by picking his successor, a position of influence that Nakasone clearly relished.

A nationalist known in his early career for his right-wing rhetoric, Nakasone was long called the "weather vane" for his seeming tendency to take positions after sensing the political winds. He headed one of the Liberal Democratic Party's smallest factions and was elected prime minister in 1982 only with the backing of Kakuei Tanaka, the so-called "shadow shogun," or political boss, who several years ago was convicted in a political corruption case.

But Nakasone's stature grew steadily, and when Tanaka was left incapacitated by a stroke in 1985, Nakasone emerged as a leader in his own right.

Nakasone made it clear at the outset that one of his main tasks would be to improve relations with the United States that had become strained under his predecessor, Zenko Suzuki.

Responding to U.S. pressure, he pushed Japan to play a larger military role in the western alliance than past prime ministers said Japan's "peace" constitution would permit. For his efforts, he is viewed as possibly the most pro-American prime minister in Japan's postwar era. He was often accused of being too eager to appease the United States.

Under Nakasone, Japan agreed to share militarily useful technology with the United States, participate in President Reagan's Strategic Defense Initiative to develop a space-based antimissile defense shield and strive to protect the sea lanes around Japan. While reducing spending in other areas, Nakasone also pushed through annual increases in his defense budgets, boosting military expeditures over 1 percent of GNP, the limit traditionally observed by past Japanese Cabinets.

Diplomats and others here credit Nakasone with helping to create a new mood in Japan. Just a few years ago, prime minister Suzuki stirred up a controversy when he used the word "alliance" in discussing relations with the United States.

However, his defense moves, coupled with his strong strain of nationalism, raised worries among opposition parties on the left and some Asian countries that he was helping to revive latent Japanese militarism. His nationalism also got him in trouble in the United States when he suggested that Japan was a more intelligent society than the United States because of the U.S.' large population of blacks, Puerto Ricans and Mexicans.

On the economic front, Nakasone had less success, particularly in dealing with Japan's largest trading partner, the United States. He spoke in favor of further liberalization of Japanese markets, went on television to encourage people to buy imports and backed an agreement to allow the yen to rise in value against the dollar, which hurt Japanese exporters. He even interceded at times to give U.S. firms better access to government contracts.

But the trade imbalance with the United States has only worsened. In 1982, the U.S. trade deficit with Japan stood at almost $19 billion. By 1986, it had grown to more than $58 billion. Trade frictions with the United States have reached levels that have alarmed the Japanese. "Nakasone has issued a number of statements, declarations and proposals to open up the market, but in my opinion they've mostly been bone and little meat," Ambassador Mansfield said.

Domestically, Nakasone's record had notable successes and some failures. His Cabinet dismantled several cumbersome government monopolies, including the national railway and telephone systems, streamlined some government agencies and began to chip away at the budget deficit.

But efforts at a tax overhaul were dropped, education reform never really was pursued and land prices were allowed to soar, making home-ownership impossible for many Japanese. For this, Nakasone was sharply criticized by the media and by many in the Diet. Nonetheless, his popularity with the public has remained astoundingly high, higher in fact that any other Japanese prime minister at the end of his term.

The explanation in part is that Nakasone, with his relatively tall build, clear speech and outspoken ways, brought a new presidential style of leadership to a Japan accustomed to the gray, undramatic leaders of the past.

The question remains whether his successor, Takeshita, an old-school, consensus-style politician more comfortable in the back rooms than in front of television cameras, will feel the need to adopt some of Nakasone's style in order to succeed at home and abroad.

Nakasone will remain a member of the Diet after stepping down as prime minister, and he has told friends that he holds out some hope of once again leading Japan. Publicly he has said only that he looks forward to joining the party ranks again and working to make the Takeshita government a success.

At a farewell news conference with foreign reporters this week, Nakasone described the prospects for his future by quoting Gen. Douglas MacArthur, who led the postwar occupation of Japan that forced changes on the country that a younger Nakasone often denounced.

Speaking in English, Nakasone said, "Old soldiers never die, they just fade away." Then he added a more home-grown expression: "From now on, I will go around picking up balls as a member of the team."