It was an extraordinary affair, the kind of debate that should have happened before Vietnam, but never did.

For three long and often emotional days, the House showed its best and worst sides as "the people's body," exploring in an unusually frank and serious manner the practicality and morality of supporting a U.S.-backed insurgency in another country.

In the end, a 228-to-195 party-line vote decided the issue, with the often-divided House Democrats showing surprising unity in cutting off aid for covert activities in Nicaragua.

The vote occurred after hours of spirited partisan debate on issues of war and peace.

The ghost of Vietnam hovered from the moment on Wednesday that Intelligence Committee Chairman Edward P. Boland (D-Mass.) rose and declared that when the House adopted the Gulf of Tonkin resolution in 1964 that led to a U.S. military escalation in Vietnam, "many of us couldn't see where it would take us."

"We couldn't. We didn't have the information," said Boland, who came to Congress in 1953. "Today the House doesn't suffer from that disadvantage. You have heard in secret session the number of fighting men armed, the cost of the program, the plans for expansion. At the same time, you know the Sandinistas aren't wearing white hats."

The debate, which began last week with a rare closed session, reached high drama yesterday. Tempers flared; members shouted and clapped as test-vote tallies were recorded.

Democratic members referred to the 20-year occupation of Nicaragua by U.S. Marines early in this century, to the aborted CIA-sponsored Bay of Pigs invasion of Cuba in 1961 and to the Gulf of Tonkin Resolution employed by President Johnson to justify military escalation in Vietnam.

Republicans spoke of the heavy U.S. stakes in Central America, including the Panama Canal and a potential tidal wave of refugees that could follow a communist takeover of additional countries in the region. They warned of abandoning the U.S.-sponsored Nicaraguan insurgency in midstream.

In one dramatic moment, Rep. Phil Gramm (R-Tex.) accused Democrats of advocating "a policy of retreat, a policy of abrogating our responsibilities, a policy of surrender."

Gramm, a former Democrat, said the party was repeating the mistakes of Vietnam by "holding back our efforts" to combat communism.

An angry Rep. Robert J. Mrazek (D-N.Y.) accused Gramm of being "an armchair general" who spent the Vietnam war on a college campus. Mrazek, who lost an eye while training as a naval officer in 1967, shouted:

"We're playing with dynamite here when it comes to the lives of another generation of Americans."

The politics of the issue were never far away. Majority Leader James C. Wright Jr. (D-Tex.), who normally favors a bipartisan approach to foreign policy, set the political problem for both parties in unusually stark terms during an interview.

"Who gets blamed if you lose Central America?" he asked. "Who gets blamed if we have a big war?"

Each party's position on covert aid was clear, however. Republicans, although grumbling that they hadn't been consulted enough about recent administration moves in the region, wanted to stick with President Reagan and continue covert assistance. Democrats, with more than a little uneasiness, sought to end it.

Outnumbered, the Republicans, as they have so often during the Reagan years, turned to a southern Democrat in hopes of saving the day. This time their man was Rep. Daniel A. Mica (D-Fla.), a former teacher and sometime "Boll Weevil" from West Palm Beach.

The GOP rallied around a Mica-drafted amendment that called for an end to covert assistance to the anti-government guerrillas in Nicaragua only if the Nicaragua government stopped supplying arms to leftist guerrillas in El Salvador.

Mica had predicted that his measure would attract enough conservative Democrats to win. But it failed, 223 to 202. Democrats jumped to their feet in applause: they had broken the coalition of Republicans and conservative Democrats that had given Reagan so many victories in the past.