A ship carrying explosives to the Nicaraguan government was searched in Costa Rica yesterday amid a flurry of press reports comparing the incident to the case of four Libyan airplanes detained in Brazil last week.

But the Costa Rican government hastened to assure reporters that while the investigation was continuing they had determined that there were no weapons aboard the ship and no law had been violated.

"We cannot say that this is like the case in Brazil," said Carlos Jimenez, spokesman for the Public Security Ministry whose agents searched the 500-ton Panamanian-registered freighter Lewbi at the Pacific port of Puntarenas. He said the ship carried 100 tons of dynamite and detonators, a "cargo that is considered normal."

Jimenez said the ship was heading from Cristobal, Panama, to the Nicaraguan Pacific coast port of Corinto and developed engine trouble Tuesday off Puntarenas. When the captain radioed to the port for permission to anchor, the radio operator thought the captain had said his cargo was agricultural chemicals, the spokesman said.

When it was discovered that the cargo was explosives, the investigation was begun, he said, but it was soon determined that the cargo was legal.

"As lovers of peace, we do not want to have problems with our neighbors to the north," he said, referring to the leftist Sandinista government of Nicaragua, which the Reagan administration has accused of backing rebel movements in other Central American countries.

"We are concerned that cases like that of the ship Lewbi create an atmosphere of sensationalism abroad when there is nothing spectacular about it," Jimenez added.

State Department spokesman Alan Romberg told reporters that the ship was "found to be carrying a large quantity of explosives . . . destined for Nicaragua."

A Nicaraguan Embassy official said no details were available about the incident but said the explosives could be used for many peaceful purposes. The official said the Reagan administration "tries to inflate situations that otherwise would never be noticed if they did not have such a desperate desire to prove something against us."

The discovery last week that four Libyan airplanes that landed in Brazil were loaded with weapons for Nicaragua was seen in Washington as bolstering the administration's contention that Nicaragua is supporting rebels in El Salvador and other Central American countries. Reagan went before a joint session of Congress last night to request support for his efforts to block the al-leged Nicaragan arms shipments to El Salvador.

The first reports from the Costa Rican Public Security Ministry yesterday said the explosives aboard the Lewbi had been purchased legally in Switzerland, but Rodrigo Peralta, an assistant spokesman, said later that information was "not official."

Peralta said the ship was still in Puntarenas yesterday, but that it was not being forcibly detained and its "documents are all in order." He said the crew members were free to come and go as they pleased, but the ship would remain in port for an investigation of "the legal aspect of the transport of explosives."

Relations between Costa Rica and Nicaragua have been tense at times during the 3 1/2 years since the Sandinistas came to power. During their fight against the dictatorship of Anastasio Somoza, the Sandinistas openly used bases in Costa Rica and troops and weapons crossed the border freely. But as some Nicaraguans became disillusioned with the revolutionary government, exiles began to move to Costa Rica and there were fears they would try to repeat the Sandinistas' use of the neighboring country as a base.

Eden Pastora, a former Sandinista commander who broke off with the Nicaraguan government, went into exile in Costa Rica and announced earlier this month that he had moved into southern Nicaragua to begin an armed rebellion. In the northern part of Nicaragua another, U.S.-backed rebel group, with bases in Honduras, is fighting the Sandinistas.