The Catholic-dominated Democratic Party claimed an upset victory in Uganda's elections tonight, but the country's military rules immediately moved to forestall any shift in power by retroactively altering the electoral rules.

The bizarre government action amounted to a coup within an election. It meant that Uganda, after a decade of brutality under dictator Idi Amin and chaos under three successor regimes, still has not achieved its first fledgling steps toward restoring democracy.

Paulo Mujwanga, chairman of the military commission that seized power in this East African country last May, issued a declaration making him the sole judge of whether elections in each of the 126 parliamentary districts were valid.

He also temporarily banned announcement of any election results, but not before the Democratic Party declared it had won a majority.

Muwanga is closely allied with former President Milton Obotge, the socialist-leaning leader of the Uganda People's Congress which was heavily favored to win the country's first elections in 18 years.

Before the elections, analysts said that failure of Obote to win could lead to a military coup since his party enjoys the support of the army.

Muwanga "has hijacked the elections," a Western diplomat said.

The capitalist-oriented Democratic Party, led by Paul Ssemogerere, put out a series of announcements during the day as ballots were counted, claiming it was headed for a landslide victory with 66 seats already in hand.

The electoral commission, which is supposed to be in charge of the election, privately confirmed to diplomats that the Democratic Party had already won an overall majority in the partial results received.

Ssemogerere, who is American-educated, told reporters at his home that he felt his Democratic Party's apparent victory was a reaction to bias toward Obote in government-controlled media and alleged malpractice carried out by his party in preventing nominations and gerrymandering constituencies.

He said he felt the elections "had not realy been fair," but "these things can be counterproductive. When there's a scandal, people react."

At the glum, virtually deserted office of Obote's Uganda People's Congress, officials claimed 36 seats, but 17 of them were uncontested.

Reversing the results could prove difficult since electoral observers from the Commonwealth, a 44-nation organization including Britain and its former colonies, issued a report tonight endorsing the elections, though with reservations.

While the report criticized many election procedures, mainly carried out by Obote's People's Congress, the Commonwealth said, "This has been a valid electoral exercise which should broadly reflect the freely expressed choice of the people of Uganda."

The approval by the Commonwealth observers, who are scheduled to fly out this weekend despite pleas by Ugandans for them to remain until a civilian government is sworn in, was seen as necessary for the new government to gain international approbation and much-needed aid.

Muwanga's action banning publication of the results contradicted the election law, which left control of the entire procedure in the hands of an independent electoral commission. His order made a farce of a statement just hours earlier to foreign correspondents by Information Minister David Anyote.

"The military commission has nothing to do with these elections," he said. "There are no facts about these elections that we will hide."

The action also presents a dilemna for Tanzanian President Julius Nyerere, a long-time supporter of fellow-socialist Obote. Nyerere still has 10,000 troops in the country as a result of the overthrow of Amin last year, and it would be embarrassing if he allowed the military commission to thwart the will of the people in a Commonwealth-approved election.

The government also banned any demonstrations tonight and the military broke up one in front of the Democratic Party headquarters. Party members managed, however, to stage celebrations at individual polling places after the vote counting confirmed their victory.

At one station, about 20 soldiers of the Ugandan army, whose loyalty lies with Obote, guarded the scene, but the party official moved the crowd several hundred feet away before making the announcement that their candidate had won by more than 4,000 votes in a total of about 4,900.

A grim-looking security official who was loyal to Obote watched the ensuing celebration and said, bleakly, "This is democracy -- thanks to Nyerere."