Japan promised today to reduce its balance of trade surplus considerably and said it would strive to wipe out the surplus completely under the terms of a U.S.-Japanese agreement that averted a major trade conflict.

The accord came after more than five months of difficult negotiations and was described by U.S. and Japanese representatives as heralding a new era of peaceful commercial relations between the two countries.

Robert Strauss, the special U.S. trade representative, told a news conference that the agreement marked a major "change of direction" on the trade front.

"We haven't solved all the problems but we have defined them and we will begin a new process which will strengthen our relationship," he said. He conceded that the result achieved here would not eliminate the protectionist movement in Congress, which seeks to cut back sharply on Japanese imports that complete with U.S. products.

Strauss added, however, the "those protectionist forces would have raged much stronger if we had not come here."

The agreement was reached at about 2 a.m. in an unusual bargaining session at a dinner party given by U.S. Ambassador Mike Mansfield. Late yesterday both sides had indicated that there might be no agreement at all. As late as 1:30 a.m. tday Strauss was telling the Japanese there would be no agreement unless his language was accepted.

Sources on both sides said that shortly before 2 a.m. today Japanese representatives made new concessions that, along with some modifications by the United States, made an agreement possible.

According to a joint statement, Japan promised to reduce its balance of trade surplus considerably and said it would strive to wipe out the surplus complety by 1979 or "thereafter"; it formally agreed to accept a deficit in its current accounts if it should occur; and it promised to reduce tariffs and make other changes to give foreign countries the same opportunities to sell in Japen as Japanese firms have in overseas markets.

Strauss called the agreement "a more far reaching result than I had antipated."

The key phrase was one that pledged Japen to a policy of achieving "equilibrium," or an end to the current accounts surplus. Japan had refused during a week or working-level talks here to include that word in any agreement, claiming that as a nation dependent on foreign trade it could not publicly proclaim a date by which it would wipe out its surplus.

There were different interpretations, however, as to how tightly the agreement bound Japan to a specific time for reaching that goal. The United States wanted it pinned down to the Japanese fiscal year that begins in April, 1979, but the final version said in 1979 "and thereafter." Japaneses sources claimed that the addition of the work "thereafter" meant there was no oblifation to hit that target in that fiscal year.

The final language stated that in fiscal year "1979, and thereafter, under present international economic conditions, all reasonable efforts would be continued with a view to further reducing Japan's current account surplus, aiming at equilibrium, with deficit accepted if it should occur."

Japanese negotiators had complained that the United States was demanding too many specific promises and that they were reluctant to commit their country on paper to a policy of eliminating trade surpluses and accepting the possibility of deficits in coming years.

The United States has complained for months about Japan's growing trade surplus - expected this year to range between $10 billion and $12 billion.

Other parts of the agreement bind the Japanese to eventual "parity" in trade relations with the world, meaning their markets ultimately are to be as open as those in other countries. It said this was to be done by making deeper future tariff cuts than negotiated formulas provide for.

One well-informed Japanese source said that he was surprised that his government gave a many concessions to the United States as it did. Prime Minister Takeo Fukuda's administration has been under heavy pressure from some quarters to avoid making specific commitments to the Americans.

The specific trade measures negotiated into the agreemtn were not surprising and do not represent any major new concessions by Japan.

It reiterated the Fukuda administration's pledge to seek a 7 per cent growth rate to stimulate domestic demand for foreign goods - a target resisted by Japan last fall but ultimately accept during Washington talks last month.

It promised that Japan would make tariff reductions of $2 billion in advance of the Geneva tariff negotiations that start later this month and to remove quota controls on 12 products. Both had been proposed previously by Japan.

The Japanese promised to treble imports of oranges and to quandruple imports of orange and grapefruit juice. Both goals are far less than the United States had demanded. It promised "mutual efforts" to increase beef imports by 10,000 tons next fiscal year, but did not bind the Japanese to that goal.

The Japanese insisted during the talks that domestic pressures prevented from allowing imports of more agricultural commodities. Even the minor concessions announced today drew an angry response from Japan's leading farmers' association, which declared that Japan had "surrendered to the unjust requirements" of the United States.

In deference to the Japanese, the agreement included a U.S. promise to improve its balance of payments position by reducing its dependence on imported oil. Japan's government has said many times that the real American trading problem is the heavy importaiton of oil, not the trade barriers in Japan.