UNITED NATIONS -- For the United Nations, 1987 proved to be a watershed year in which the institution came within days of bankruptcy, and yet began a political resurgence as a forum used once again by the major powers to deal with significant global issues, diplomats and U.N. officials said this week.

They noted that the United Nations had been the catalyst in efforts to coordinate responses to the new threat of famine in Africa, and the economic crisis facing many governments there. Its World Health Organization has been instrumental in spurring national programs to cope with the AIDS epidemic and to formulate uniform policies. The U.N. Environment Program helped reach the first international agreement on steps to preserve the ozone layer.

In the political arena, where governments had bypassed the organization for years in their efforts at problem-solving, U.N. institutions or officials have played central roles in attempts to stop wars in the Persian Gulf, Central America and Afghanistan.

The United Nations' financial crisis was largely the result of funds withheld by the U.S. Congress, motivated by fiscal considerations as well as a political campaign by conservative groups seeking to impose constraints on the institution for what were perceived as anti-American resolutions.

At one point in 1987, the United States owed a cumulative total of $414 million to the United Nations, and until the end of November it had paid only $10 million of its $212 million regular budget assessment for the year, which is a quarter of the organization's annual budget. Even the United Nations' friends on Capitol Hill warned that the final U.S. appropriation might provide less than $90 million, and might impose new political restrictions.

Secretary General Javier Perez de Cuellar warned that the United Nations would go bankrupt in mid-December if the U.S. funds did not arrive, and asked for authority to sell bonds on commercial markets.

But, almost magically, said American officials and U.N. budget officers, the mood on Capitol Hill changed. As funds for others were being slashed, allocations for 44 international organizations were increased far beyond expectations, to provide the United Nations with between $150 million and $160 million for 1987 -- still $50 million below what was owed, but more than enough to meet the payrolls.

Equally important, the amount was viewed by both western and Third World diplomats as sufficient to sustain the credibility of a gentlemen's agreement designed to resolve the long-range budget crisis.

That pact envisions a streamlining of the U.N. bureaucracy -- which has already begun -- and consensus decisions on future U.N. budgets, giving the Americans and other major donors a larger say in how much is spent and what it is spent on. In return, the donors are expected to pay what they owe.

American officials and those at the United Nations who monitor the Congress suggested that the pendulum had swung away from U.N.-bashing on Capitol Hill, as it had more than a year earlier in the Reagan administration. The reasons, they said, include the departure of hard-liner Alan L. Keyes as assistant secretary of state for international organization affairs, intense and credible lobbying by U.N. Ambassador Vernon A. Walters, and a growing acceptance of the administration position that the world body is becoming a useful mechanism in the Persian Gulf and in advancing other U.S. interests.

There was also the awareness that the Soviet Union, the major U.N. debtor for the organization's first 40 years, paid its dues in full in 1987 and announced that it would shortly pay the $200 million it owes on peace-keeping assessments dating back to the Congo and Sinai operations of the 1950s and '60s.

The Soviet fiscal turnabout was part of what appeared to be a larger policy change initiated by Kremlin leader Mikhail Gorbachev, who in a September article envisioned a larger U.N. role in resolving a wide range of political disputes involving the two superpowers. A Soviet-American convergence, which is needed before the United Nations can effectively address regional issues, was advanced by last month's summit meeting between Gorbachev and President Reagan.

The most tangible expression of that shift toward a more central U.N. role in world affairs began last January, after Perez de Cuellar urged the major powers to take a more active role in dealing with the war between Iran and Iraq, then in its seventh year. For the first time in history, the Security Council's five permanent members -- Britain, China, France, the Soviet Union and the United States -- convened in private and negotiated a resolution, adopted unanimously on July 20 by the full 15-member council, demanding a cease-fire in the war.

The Persian Gulf is just one area in which the use of U.N. peace-keeping forces, virtually moribund for the last decade, is envisioned as a mechanism to help restore peace.

The peace plan signed Aug. 7 by the five Central American presidents calls for the use of U.N. observers as an arm of the commission monitoring compliance with the pact. A recent U.N. report revealed that refusal by Honduras to grant observers free access to military camps used by Nicaraguan rebels fighting the Sandinista government is delaying the dispatch of monitors.

A peace plan for Afghanistan being negotiated by U.N. Undersecretary Diego Cordovez also calls for U.N. observers to monitor both a Soviet troop withdrawal and a pledge to bar the flow of arms and men across Afghan borders.

Another major boon to the United Nations' image was Perez de Cuellar's decision in November to open to public scrutiny the archives of the U.N. War Crimes Commission, which disbanded in 1948 after compiling dossiers on German and Japanese war criminals. One of the files dealt with former U.N. secretary general Kurt Waldheim, now president of Austria.