Japan's ruling Liberal Democratic Party has gained five seats in a local Tokyo election that is watched closely here as a barometer of national voter sentiments, according to results released today.

The country's main opposition group, the Japanese Socialist Party lost four seats in yesterday's voting, which selected a new 127-member metropolitan assembly. The Japanese Communist Party gained three.

The shift by voters buoyed spirits within the ranks of the ruling party in Tokyo, which is traditionally an opposition stronghold. "They voted from a realistic, not an ideological point of view," said Koji Kakizawa, a Liberal Democratic member of the lower house of the Diet, or parliament.

It was also good news for Prime Minister Yasuhiro Nakasone, whose leadership of the ruling party, a conservative, probusiness coalition despite its name, faces constant challenges from rivals within. Nakasone today called it "an expression of support for the LDP."

Nakasone is now considering when to call new elections for the lower house. Newspapers here are speculating that it could be as early as this fall, and some Japanese felt today's results might favor such a decision.

By other accounts, however, the election is not likely to come until next June, when an election for the upper house of the Diet is scheduled. Putting the two together would have the effect of increasing turnout, the reasoning goes, which tends to favor the Liberal Democrats.

Yesterday's voting, conducted under cloudy skies, had a record low turnout of 53.5 percent.

The voting was the latest in a long string of setbacks for the Socialists, whose leaders in recent years have been trying to revitalize the party by abandoning much of its ideology and adopting a more mainstream approach.

Analysts attributed the Communists' gains to a strong party structure that got large numbers of voters to the polls despite the low turnout. A two-seat gain by the Komeito, or Clean Government Party, an arm of the conservative Buddhist organization Soka Gakkai, was also credited to good organization.

The Liberal Democrats still will fall short of a majority in the Tokyo assembly but are expected to continue control of it through a conservative coalition around Gov. Shunichi Suzuki.

Leaders of all significant national parties appeared at rallies to deliver endorsements of their party's candidates and promote the bodies' national policies. Nakasone campaigned unusually hard, appearing during four of the campaign's nine days.