Mexico's decision to nationalize all private banks and to impose general exchange controls caught U.S. officials and bankers by surprise yesterday, despite their close involvement in an international rescue package to bail out the nearly bankrupt country.

Treasury Secretary Donald T. Regan told reporters, "We were not advised in advance." Senior Federal Reserve officials also said the decision came as a complete surprise to them.

Mexico, the largest borrower in the developing world with about $80 billion of outstanding foreign debt, already has received some emergency cash from the U.S. and other governments to help it pay for imports and meet its immediate debt commitments.

In the middle of August, the country came close to running out of foreign cash as foreign bankers became unwilling to continue lending it new money and Mexicans transferred cash out of the country. Mexico was forced to seek international aid to stay afloat. It is still negotiating for longer term help with the International Monetary Fund and the more than 1,000 private banks to which it owes money.

Yesterday's new measures, announced by President Jose Lopez Portillo in his last State of the Union address before he steps down in December, were the latest in a series taken to try to halt the flow of pesos out of Mexico and to deal with the nation's financial crisis.

The Mexican peso has lost about 80 percent of its value against the U.S. dollar since the beginning of this year, with two devaluations before the peso was floated three weeks ago and a three-tier exchange rate system put in place.

Some U.S. bankers suggested yesterday that the bank nationalization, although presented as a move to punish banks for aiding speculation against the currency, may have been triggered partly by the fear that Mexico's commercial banks were near failure. Many of their customers are going bankrupt as they are faced with a huge increase in the peso value of their foreign exchange debts.According to one U.S. banker, banks also are unable to meet their own dollar debts or raise new money across the border.

Lopez Portillo said that Mexican banks would be closed today and tomorrow and would reopen on Monday with the new ownership and controls.

Mexico's latest move added "one more issue" to an already long list to be negotiated by Mexico and the IMF, one monetary official said yesterday. Agreement between the two is seen as crucial to the rest of the rescue package for Mexico, and in particular to the negotiations with commercial banks about stretching out its debt to foreign banks.

It will be very difficult to reach such agreement before the new government takes over in December, one source said yesterday. Mexican officials have said they hope to get IMF money next month.

There was still considerable confusion yesterday about how the new controls would operate, and why the government had decided to nationalize the banking system as well as to tighten control on foreign exchange transactions.

Many developing countries, and some developed nations, have some form of exchange controls to ration a limited supply of foreign exchange. Such controls are aimed at stopping private citizens and businesses from buying foreign currency freely, and limiting their ability to take money out of the country, or to hold onto foreign exchange, which they may earn from selling goods overseas.

Mexico has been the exception to this rule until now, one monetary official pointed out yesterday. However, "if you are hard up for foreign exchange" then "you will take it while you can," one U.S. official commented yesterday.

The new controls could aim to force businesses with dollar earnings to turn these over to the government, one expert said. Several Mexican companies have been paying dollars they have earned directly to their creditors or keeping them in American bank accounts, sources in Mexico City said yesterday.

The new controls probably will also limit all Mexicans' access to foreign exchange whether to buy imports, make payments on their debt, or to invest in U.S. real estate.

In the past, the Mexicans and others have argued that the close ties between the United States and Mexico and the long joint border would make it impossible to enforce exchange controls. It's still possible for private citizens in Mexico to evade controls and take advantage of the border to bring money physically into the United States, one international official commented yesterday.

However, another pointed out that money is not usually moved by physically carrying bank notes out of a country. The Mexican government believes that it would be easier to administer controls on other transactions if the banks are nationalized, although bank regulations in many countries mean that the central bank can control private banks as effectively as if they are nationalized, one offical said.

Lopez Portillo yesterday blamed private banks for helping to precipitate the nation's foreign exchange crisis by encouraging their clients to invest in dollars and drain money out of Mexico.

Several countries, including France and India, have nationalized banking systems.