After years of sporadic negotiations made difficult by a fear of Soviet anger, the Japanese government last night appeared to be ready to sign a peace and friendship treaty with China.

Unless there is a last-minute hitch, Japanese officials said, the treaty will be signed today in Peking where three weeks of negotiations apparently have resolved a dispute over whether the pact is directed against the Soviet Union.

Despite Japan's insistence that Moscow is not a target, officials here were concerned about a possible reprisal designed to show Soviet irritation over Japan's closer relations with China.

In Moscow, the Soviet news agency Tass warned that "conclusion of the treaty on Chinese terms may not only cause serious damage to Japan's national interests, but also hinder the development of the detente process and heat up the international situation to the utmost."

The commentary, published in the Communist Party newspaper Pravda, was the latest in a series of attacks on the proposed treaty. Moscow objects in particular to China's insistence that the treaty contain a clause apposing the "hedgemony" of any other powers in Asia - a clause clearly directed at the Soviet Union.

Prime Minister Takeo Fukuda spent the day attempting to gather support among party elders for the treaty, working hardest to placate the Liberal Democratic party's right wing, which is suspicious of any close alignment with a Communist nation.

For Japan, the treaty's importance is largely symbolic. The pact would not specify any new undertakings between the two governments but would merely spell out a policy of peace and friendship in general terms.

The only sticking point was China's insistance that the treaty put both countries on record as opposing the dominance is Asia of any other country.

Japan trying to maintain peaceful relations with both Communist powers, initially opposed this so-called antihegemony clause.

According to versions appearing in the Japanese press yesterday, the hurdle was overcome by an agreement to include an additonal clause stating that the treaty will not affect relations between China or Japan and any third country.

The compromise was being pictured by Japanese officials as a victory by Foreign Minister Sunao Sonoda, who went to Peking Tuesday for the final rounds of talks - with his Chinese counterpart, Huang Hua, and with Deputy Premier Teng Hsiao-ping.

The chief secretary of the Japanese Cabinet, Shintaro Abe, said yesterday that basic agreement has been reached in Peking and that both sides are satisfied. No comment from the Chinese side has been published here, except for occasional official news reports stating that the talks were proceeding in a friendly atmosphere.

Abe said that the final result will show that Japan is not swerving from its postwar policy of having friendly relations with all countries.

Soviet displeasure was made clear in June when the ambassador to Japan, Dmitri Polyansky, delivered a protest to the Foreign Ministry here. He said that by signing the treaty Japan would be pulled into "an anti-Soviet alliance with China."

He warned vaguely that if Japan took any action which "impedes that future development of relations with the Soviet Union," his country might have to revise its policy of friendship toward Japan.

Some Japanese observers believe that a recent stiffening Soviet attitude in fishery negotiations between the two is part of a campaign to avert a treaty signing. It has also been suggested that recent Soviet military maneuvers north of Japan have been part of that campaign, although on high-ranking Defense Agency source said recently those maneuvers were not related to the China negotiations.

The treaty was first established as a goal of both China and Japan in 1972 when the two countries issued a communique normalizing relations. But negotiations were broken off in 1975 because of Japan's fear of Soviet opposition. Fukuda, whose ambivalence on the issue was apparent, finally announced in June that the negotiations would be resumed on July 21.

Two Chinese actions this year appeared for a while to have stymied the process. One was the sudden appearance last April of armed Chinese fishing boats near the Senkaku Islands, an area claimed by both countries and Taiwan. China later strongly deplored an agreement by Japan and South Korea for joint development of oil resources in a continental shelf area also subject to disputed claims.

The hawkish rightwing of Fukuda's party raised objections this week to any treaty that does not settle in Japan's favor the question of which country was title to the Senkaku Islands.

In a cumbersome consensus-building process this week, Fukuda has also sought to placate the party's executive board chairman, Yasuhiro nakasone, a prominent rightist politician and potential rival who has insisted that the treaty must defend Japan's territorial interests.

Meanwhile, Agence France-Presse reported that Toshio Komoto, minister for international trade and industry, will visit Chinese leaders on ways to boost bilateral economics cooperation. Ministry sources said the discussions would center on Japanese imports of Chinese crude oil after 1982, when an existing trade agreement will expire.