A bid by Ghana's military rulers to move gradually toward civilian government has been dealt a sharp setback that is likely to deepen the malaise over the army's future role in the politics of that troubled West African nation.

A nationwide referendum last Thursday on a proposed "union government" appears to have won the support of only slightly more than half the voters. Moreover, a secret ballot count has led to allegations by the civilian opposition that the results were rigged.

On Tuesday, the military government moved to crush the civilian opposition by banning the three movements that had been campaigning against the proposal. In addition, there are reports that at least 28 opposition leaders have been arrested.

The final outcome of the referendum is still somewhat confused. Reports from the Ghanaian capital, Accra have said variously that 53, 56 and 64 percent of the participants voted for the union government. Such a low percentage in favor of a government-sponsored referendum is extremely rare in Africa.

There were 4.6 million voters registered for the referendum, but the exact number of those who cast ballots is also unclear, with reports varying from less than 2 million to more than 4 million.

The latest figures given by Ghana Radio yesterday were 1,983,000 voting, with 1,103,000 casting ballots in favor of the union government and 880,000 against it.

The military's proposal for the union government provides for the restoration of constitutional rule in Ghana by mid-1979. Under the plan, army officers would play a still unspecified role in some kind of partnership with civilian politicians without political parties. Opponents of the scheme say it is simply a disguised method of perpetuating military control of the government.

Doubts about the honesty of the referendum were apparently heightened after Gen. Kutu Acheampong, head of the Supreme Military Council, fired his electoral commissioner the day of the referendum for demanding that the counting of ballots be done in public.

The military's conduct of the referendum is being watched closely here since Nigeria, like Ghana, is presently ruled by officers who hve pledged to return the country to civilian control by next year.

The reaction here has been sharp and angry.

"Only banana republics banish their electoral commissioners, appoint their man to count the votes in private and expect the world to swallow the dubious results" said the Daily Times, Nigeria's leading newspaper.

Calling this a "rape of democracy," the Times predicted that since Ghana was not a "banana republic" but "Africa's black star," the people would "soon assert their right to choose freely their leaders."

Whether this will now happen remains to be seen after the banning of opposition groups. The three groups outlawed were the People's Movement for Freedom and Justice led by retired Maj. Gen. Akwesi Afrifa, a former chief of state, the Third Forces and the Front for Prevention of Dictatorship.

The opposition is made up of students, professionals, some intellectuals associated with Ghana's first deposed civilian president, Kwame Nkrumah, and old-guard politicians and their supporters from previous ousted military and civilian governments.

Last summer, students and professionals went on strike and nearly succeeded in toppling Acheampong's government, which led the military to move toward a return to civilian rule. Achaempong seized power in January 1972, overthrowing the second civilian government Ghana had since its independence in 1958.

It is still not clear just how such a government would function, but a constituent assembly is supposed to be set up next to draft a new constitution and work out the details for it.

This schedule may be upset, however, by the reaction to the referendum. Reports reaching here said that the professionals and students, many of whom are already absent from classes, were now planning another strike to protest the referendum.

Such a strike is certain to touch off a confrontation with the military government that is likely to impose stiff measures resulting in a wave of civil strife throughout the country.