Prime Minister Takeo Fukuda abruptly abandoned his reelection campaign today after suffering a stunning loss in preliminary voting by members of the Liberal Democratic Party.

His withdrawal meant the almost certain election of his main rival, Masayoshi Ohira, who earlier in the day had pulled off an unexpected victory in voting by some 1.3 million members.

In a brief news conference several hours after the returns were counted, Fukuda, 73, expressed surprise at his loss and said he would not try to salvage victory in the decisive election Friday by party members serving in the Japanese parliament.

"My decision is that I will not be a candidate in the main election." he said.

He declined to speculate on why he had lost.

"Generals of defeated armies do not speak about their strategy," he said, quoting a Japanese proverb.

Ohira's ascendancy is not expected to cause any sharp changes in Japanese policy. With minor disagreements, he generally has followed lines laid down by Fukuda's administration and the campaign exposed few differences between them.

[In Washington, the State Department expressed confidence that the change in leadership will not affect friendly relations between Japan and the United States.]

Fukuda, who took office two years ago, became the first post-war Japanese prime minister to lose his position as a result of a party election. Others have resigned, sometimes under pressure or have served out their terms and retired.

The election today was a kind of advisory primary - the first in Japan's history - in which 1.3 million party members chose among four candidates. The two leading candidates were supposed to face each other Friday in a vote only among party members in parliament.

Officially, both elections were to choose a party president who then is automatically elected prime minister by the whole parliament.

The final returns showed that Fukuda got 472,523 votes to Ohira's 550,891. Two other candidates, Yasuhiro Nakasone and Toshio Komoto, split the remainder and were automatically eliminated.

Fukuda technically could have remained in the contest and fought out the second election among his party's parliament members. But ironically, he was forced by his own election strategy to bow out and leave the field uncontested to Ohira.

The pre-election predictions made Fukuda seem to be a sure winner. Polls by three Japanese newspapers showed him winning, although by a diminishing margin as the campaign proceeded.

Knowing that he faced a bruising battle with Ohira in the second election, Fukuda had suggested last week that both candidates agree to abide by the decision of voters in the first. Ohira rejected the idea. But today, when the votes were counted, Fukuda was trapped by his own words and had to withdraw.

"Today I saw the results and speaking frankly I was quite surprised," Fukuda told reporters. "I have thought deeply about that and as I have always said we should respect the results of the first election and I will do exactly that. My decision is that I will not be a candidate in the main election and for today that's good enough."

Fukuda's defeat also represented a show of force by his longtime, rival, former prime minister Kakuei Tanaka, who was forced to resign after a money-and-politics scandal in 1974.

Tanaka, who also is still on trial in the Lockheed scandal, retains a sizable Liberal Democratic Party following and he apparently used all his resources to help Ohira gain his upset. Ohira ran strong in many of the 47 prefectures where Tanaka is still revered.

It developed into a dirty campaign, with Fukuda implying last week that Ohira and Tanaka forces were using money and other improper means to win votes. It also was charged that someone illegally "leaked" a list of party members to Ohira's group, enabling it to canvass extensively for support.

Ohira's main point of attack on the incumbent's policies was a claim that Fukuda used too much force and confrontation in dealing with opponents, including the opposition parties. Ohira promised to stress negotiation and compromise and seek to develop a consensus with the opposition parties.

Ohira, 68, and Fukuda are cut from the same mold. Both began their careers as Fianance Ministry bureaucrats. Some Japanese commentators have described Ohira as a bit more liberal in domestic policy than Fukuda. And Ohira has not been quite as intent as Fukuda on generating interest in building up Japan's defense forces. But on the whole their differences are small.

Ohira holds the influential position of secretary general of the Liberal Democratic Party, the base from which he made his successful challenge this year. He declined to speculate on what direction his government would take, saying his first task is to unite the party to face Japan's domestic and international problems.

Ohira expressed gratitude that Fukuda had followed his own words and withdrawn before the second election. He said he thought Fukuda had taken that course to avoid "chaos" in the party, referring to the possibility of a bitter struggle if the choice had been left up to the party's members of parliament.

Spokesman for Japanese business interests generally expressed approval of Ohira, calling on him to lead a campaign to control inflation and promote economic recovery.They said they saw no indication of any major change in economic policies.

Japan's small and splintered opposition parties predictably denounced Ohira, some of their spokesmen asserting that he won because of what they termed "money politics," meaning alleged misuse of campaign funds.

The party's members in parliament are expected to meet quickly to formalize Ohira's election as party president. Technically, the entire parliament subsequently could refuse to name Ohira as prime minister and some small opposition parties were promoting the idea of a united front to defeat him. But the chances of his being rejected are small.

For Fukuda, the election results were a stunning rejection, coming at a time when his administration was enjoying a relatively high degree of popularity. A year ago he was in disrepute because of Japan's prolonged economic troubles, topped off by a soaring trade surplus that caused endless arguments with the United States and Europe.

But Fukuda came back this year to win praise for a series of international developments, the most important being the signing of a treaty of peace and friendship with China. He was preparing to host next year's economic summit meeting of industrial democratic countries in Tokyo, another sign that he was trying to emerge as a world leader.

The election that brought him down was an unusual affair. In the past, the party presidency has been decided only by its members in parliament. After the money and politics scandal of the early 1970s, it was decided to broaden the election process to include a preferential primary. Anyone could vote in it by joining the party for a fee of about $7.50.

The primary was used for the first time this year. There were charges that some of the 1.5 million who signed up had been paid by parliamentary factions and there also were allegations that phony names were listed.