BUENOS AIRES, Argentina (AP) _ President Alan Garcia of Peru pledged Friday to break relations with any country that invades Nicaragua and help defend the leftist-ruled Central American nation.

He did not name a potential invader, but his reference to the United States was clear. The Reagan administration supports guerrillas fighting the Nicaraguan government, which often has predicted a U.S. invasion.

''An act of hostility and of intervention in Nicaragua will be an act of hostility and intervention in all of Latin America,'' Garcia said in an hour- long speech to Congress at the beginning of a three-day official visit to Argentina.

''I announce the decision of the government of Peru, in the event that foreign forces invade Nicaragua, to break relations with the aggressive power and make all efforts in defense of a brother country.''

His comments brought loud applause from the congressmen and other Argentine dignitaries in the audience.

''Some can say that in Nicaragua there is no pluralism, that the opposition isn't listened to, that there is no free press,'' the Peruvian leader said, reading from a text. ''Others will respond with the argument that the acts being carried out have created such a situation.

''We firmly believe in pluralistic democracy. But no one, and much less anyone from outside Latin America, has the right to correctively judge a process arising to overcome a totalitarian dictatorship about which nothing was said earlier.''

Peru and Argentina are among eight Latin American countries involved with the Contadora peace process for Central America. They have recommended demilitarization of the troubled region, including an end to U.S. aid for the Contra rebels in Nicaragua.

The Reagan administration views the Sandinistas as a totalitarian regime bent on spreading Marxist revolution in Central America, and is seeking congressional approval for $100 million in aid to the Contras.

The Sandinistas overthrew the U.S.-backed government of rightist President Anastasio Somoza in July 1979 after a year-long civil war.

Several governments in Latin America and elsewhere have publicly opposed military action against Nicaragua, but Garcia's was the most explicit comment.

U.S. officials denied any plans to invade Nicaragua, but the administration's military buildup in neighboring Honduras has contributed to the concern.

Garcia also criticized what he called interference by wealthy countries in Latin America's troubled economies. The region is struggling with a $370 billion foreign debt, most of it owed to private banks in the United States and Western Europe.

He said industrialized nations have imposed economic policy on Latin America while draining it of capital through debt service.

''We are called upon to press forward with a Latin American concept of development and leave behind the foreign dictation of economic theories,'' he said. ''That (foreign) approach has taken us into a dead-end alley and stolen our independence.''

Garcia has given Peru the toughest stance of any Latin American debtor, declaring when he assumed office last July that he would limit debt payments to 10 percent of export earnings.

Peru's foreign debt is $14 billion. Argentina owes $50 billion.