The 12th annual economic summit concluded its formal sessions today with a declaration admitting that continued massive imbalances in the trade deficits and surpluses among major trading nations "present an increasing threat to world economic growth."

After initial concern with the Soviet nuclear accident and ways of coping with state-sponsored terrorism, the three-day meeting of seven heads of state or government swung around in its last two days to the more typical agenda of international economic problems.

President Reagan and the leaders of host Japan, Britain, West Germany, France, Italy and Canada reached a detailed agreement to control sharp fluctuations in exchange rates, as predicted yesterday by Treasury Secretary James A. Baker III. But they failed to reach an understanding on other key proposals to deal with the problems of international trade and economic growth.

The declaration avoided direct mention of the American budget deficit, the Japanese and West German trade surpluses, or the high West German unemployment rate.

Tokyo's massive security measures for the conference were tested by the ineffectual firing of rockets toward the site on Sunday and by placement of incendiary devices at points in the subway system last night and early this morning. Trains were halted for 15 minutes but no damage was reported.

After conclusion of the summit, President Reagan extended his series of bilateral meetings to include French President Francois Mitterrand. Although France refused transit to U.S. bombers in last month's raid on Libya, Mitterrand was reported as saying today that France would be in the "front ranks" of international efforts against terrorism.

The new monetary agreement provides for more frequent meetings of major trading nations to review economic performance with the aim of stabilizing exchange rates. The added meetings are to include Italy and Canada, which had been excluded from an initial meeting for this purpose held last year in New York.

As was true at the Bonn summit last year, the seven nations meeting here failed to establish a specific date for launching of a new round of trade negotiations, although summit participants said their understanding is that work will begin in September.

But U.S. officials expressed disappointment at what they said was French refusal to incorporate the September date for the actual beginning of the new round.

Another negative element for the United States was the omission of agriculture from the list of issues to be addressed in the new round. The trade negotiations are to cover three subjects that the United States has insisted should be included: trade in services, intellectual property rights (such as trademarks, patents and copyrights), and foreign direct investment.

Both Baker and British Prime Minister Margaret Thatcher said in post-summit press conferences that agriculture would have to be on the agenda when actual trade negotiations begin.

The Tokyo economic declaration failed to include a call for Japan and West Germany to expand their economies, although that was announced as a major American objective. Instead, only very general language was used to suggest that all of the countries need to do better to achieve greater growth and lower unemployment.

In one breakthrough, the leaders expressed concern over the pileup of agricultural surpluses, a result of subsidies and protective national policies. This subject had been taboo at summits until now.

However, the leaders arrived at no solutions to the problem of farm surpluses -- and as politicians, they were careful to recognize "the importance of agriculture to the well-being of rural communites." But they added that when farm surpluses develop, "action is needed to redirect policies and adjust structure of agricultural production in the light of world demand."

There was no indication in the declaration, or in the results of bilateral conferences, of resolution of the agricultural dispute between the United States and the European Community that Baker had said prior to coming here "is the No. 1 threat to the world trading system."

U.S. officials estimate that American farmers will lose $1 billion annually in exports to Portugal and Spain as a result of their joining the community and coming under its protectionist tariff policies. The United States is to impose retaliatory measures this month.

Nonetheless, Baker said that the administration feels it comes away better armed to deal with the protectionist threat in Congress. He cited the agreement to overhaul the international monetary system, predicting that it will lead to "greater stability" of exchange rates and the broader charter for trade negotiations, even without agriculture.

"There sure is a lot more than we had when we came to Tokyo to blunt protectionism," Baker said.

The declaration made no demands that the Japanese yen appreciate further, although American and European officials say it must for large Japanese surpluses to come down. The yen appreciated 42 percent against the dollar in the past seven months.

Instead, the declaration cited "the large domestic and external imbalances" within the global economy, as well as persistent protectionist pressures, as obstacles that must be overcome.

The declaration asserted that improved economic coordination among the rich countries would help the poor nations by lowering interest rates and improving sales of Third World exports.

One suggestion to which "we attach great importance," the seven leaders said, is a "substantial" new sum of money for the World Bank's subsidized aid affiliate, the International Development Association. They also urged a general capital increase for the World Bank "when appropriate."

On Third World debt problems, there was only the expected endorsement of the Baker debt initiative, which calls for $29 billion in new loans over the next three years to 15 major debtor nations from the multilateral development banks and commercial banks.

As Japanese Prime Minister Yasuhiro Nakasone had planned from the start, the declaration cited the recent gains in the world economy -- lower interest rates, declining oil prices, reduced inflation, and "a significant shift in the pattern of exchange rates which better reflects fundamental economic conditions."

Actually, Nakasone had been saying in the weeks preceding the summit that the rapid appreciation of the yen had become excessive. The yen showed strength today unprecedented in modern times, trading at 165 to the dollar.

Nakasone said in a closing press conference that Japan would study the new monetary agreement to see how it might be used "to help overcome the problem" of the rapidly appreciating yen.

The comments of participants and observers indicated that Baker's initiative to overhaul the monetary system through new surveillance procedures among the Group of Five nations, and thus to create greater exchange-rate stability, was the outstanding economic achievement of the summit.

In addition, these five nations -- the United States, Japan, West Germany, Britain, and France -- will be joined by Italy and Canada in a summit-created Group of Seven finance ministers and central bankers that will meet at least once a year between summits.

Canadian and Italian officials welcomed this change, pointing out that they were excluded from the meeting of the Group of Five last September that agreed on actions to depress the U.S. dollar and led, in effect, to a devaluation of the Canadian currency.

But the new plan did not win unreserved endorsement. West German Economics Minister Martin Bangemann said his government had fought to limit the possibility of automatic intervention to adjust exchange rates. He said that the Germans feared such a system would force stimulation of the German economy against its wishes.

Baker said the agreement "builds" on that achieved by the Group of Five in September and strengthens it by making the system more permanent, with more frequent meetings, and by requiring the nations to measure performance against specific economic indicators, including exchange rates.

Thatcher praised the new Baker initiative -- as well as Baker's leadership -- referring to the new system as a "managed float."

The managed float -- a system that moderates the existing freely floating system without going back to fixed rates -- is intended to provide greater stability and predictability of exchange rates, especially as an aid to businessmen making plans to export or import goods.

The first of the summit's noneconomic deliberations called for countries with atomic power plants to assure "prompt provision of detailed and complete information on nuclear emergencies and accidents."

A declaration on terrorism deplored its spread since last year's meeting, "in particular its blatant and cynical use as an instrument of government policy."