President Reagan yesterday ended a five-day Latin American trip aimed at promoting hemispheric democracy by warmly praising the general in Guatemala who seized power in a coup in March and hinting that he would support a resumption of U.S. military aid to that country.

En route to Andrews Air Force base, where he landed last night, Reagan told reporters that Gen. Efrain Rios Montt was getting a "bum rap" and "is totally dedicated to democracy in Guatemala."

Secretary of State George P. Shultz said in San Pedro Sula, Honduras, before the departure of the presidential party that the Guatemalan president had told Reagan during a private, 45-minute meeting that he intended to issue the "publication of the law" governing elections on March 23, the anniversary of the coup that brought him to power.

"And precisely what that meant, I'm not too sure," Shultz added, confirming that administration officials had not pressed Rios Montt on a timetable for free elections.

In a news conference later, Rios Montt said in response to a question that the elections probably will be held by the end of 1983, repeating for apparent emphasis the word "probably."

U.S. military aid to Guatemala was suspended in 1977 because of reports of widespread human rights violations there. Since Rios Montt came to power, international human rights organizations have continued to accuse the Guatemalan armed forces of abuses, including massacres of peasants, in combating a leftist insurgency.

Asked on Air Force One on his return home whether he would restore military aid, Reagan replied: "This is going to depend, of course, on this information he Rios Montt has provided us. Yes, I would think so."

Reagan did not specify what information Rios Montt had provided. But his references seemed to indicate that the Guatemalan president stressed, as Reagan did, that the Guatemalan regime is under heavy pressure from left-wing guerrillas.

Speaking to reporters in an airport hangar before leaving Honduras, Reagan described Rios Montt as "a man of great personal integrity" who faced "a brutal challenge from guerrillas armed and supported by others outside Guatemala."

The Guatemalan president declared after his meeting with Reagan that he and the U.S. president "agree on the necessity to search for democratization and maintain it."

Rios Montt's government wants restoration of military aid, particularly helicopters, to combat the leftists. A Reagan administration official said that no decision on the aid was likely to be made before January.

Upon his arrival in Honduras, where Reagan also met with Honduran President Roberto Suazo Cordoba, Rios Montt issued a statement saying "the self-proclaimed socialist parties would be recognized" and allowed to participate in the electoral process in Guatemala.

This vague promise of constitutional elections with no timetable attached was similar to the pledge made by the leftist Sandinistas when they took over Nicaragua in 1979. No elections have been held since in Nicaragua, and Reagan has sought to underscore his administration's attempts to isolate Nicaragua by meeting with leaders of four neighboring Central American countries during the past two days.

Before traveling to Honduras yesterday, Reagan sharply criticized Nicaragua without mentioning the Sandinistas by name as he revived old anticommunist themes during a speech in San Jose, Costa Rica, that was televised to 15 nations in the region. Reagan put down a Marxist member of the national assembly who sought to interrupt him during his address.

The meeting with Rios Montt caused some discomfort in Costa Rica, a constitutional democracy, after U.S. officials pressed for a meeting there of Reagan and the other Central American leaders that he met, senior Costa Rican officials said. Costa Rican President Luis Alberto Monge told reporters the summit was ruled out in part because "I personally have not had such close relations with the Guatemalan president."

Reagan also stressed anticommunism in his weekly Saturday radio speech to the United States, where the president denounced "counterfeit revolutionaries" and made a pitch for his $1 billion program of economic and military aid known as the Caribbean Basin Initiative.

"The United States will continue to support the new democratic institutions in Honduras and the developing democratic processes of El Salvador," Reagan said in the San Jose speech, which marked the signing of an extradition treaty between the United States and Costa Rica. "Any nation destabilizing its neighbors by protecting guerrillas and exporting violence should forfeit close and fruitful relations with the people of the United States of America -- and with any people who truly love peace and freedom."

A Reagan administration official said that this passage applied to both Nicaragua and Cuba, which the State Department has accused of trying to promote revolutions in Central America. Some observers noted that Reagan's comments also could have been applied to Honduras, where anti-Sandinista rebels used camps until recently to launch cross-border raids into Nicaragua.

The Nicaraguan government has accused the United States of financing the rebels. The Honduran Army recently began a new policy of dismantling the camps in a move that apparently was timed to coincide with Reagan's visit.

The occasion for Reagan's speech to the Costa Rican legislators in San Jose was the signing of a U.S.-Costa Rican extradition treaty. A number of U.S. fugitives, including international financier Robert Vesco, have sought asylum in Costa Rica, because of the absence of such a treaty.

When Reagan rose to address the Costa Rican legislators and their guests, Sergio Erik Ardon, a Marxist member of the National Assembly, stood up in the balcony and began to talk loudly to him in Spanish. Ardon said that interrupting the speech was the only way that he could bring to Reagan's attention a letter he had written on National Assembly stationery attacking "the militarization of Central America" and what he called the U.S. policy of attaching conditions to its economic assistance to the region.

Ardon was shouted down but allowed to remain in the theater. Responding with the finesse he has often demonstrated when heckled during political campaigns in the United States, Reagan said:

"I, of course, could not understand without interpretation, but I was informed that he was expressing the communist viewpoint." Referring to the interruption, Reagan said, "He was allowed to do so here in this democracy. He wouldn't be allowed to do so in a communist country."

Reagan received a standing ovation and then repeated a joke he said had been told him by a refugee from the Soviet Union and was widespread among the people of Moscow: "If an opposition party should be allowed in the Soviet Union, they would still be a one-party country because everyone would join the opposition."

Costa Rican president Monge, who has visited Washington twice this year, warmly praised Reagan in an exchange of toasts today.

But even Monge, considered pro-American, referred obliquely to the damage done to hemispheric cooperation by U.S. support of Britain in the Falkland Islands war.