Uganda reaped the price of years of misrule today as the country's first general election since 1962 broke down in chaos and angry demonstrations here in the capital.

Voting was due to close at 6 p.m. in parliamentary elections aimed at returning the country to legitimacy after eight years of dictatorship under Idi Amin. But many polling stations around the capital had not even been able to open by late afternoon because of a lack of ballots, boxes and other materials.

As a result, tens of thousands of disgruntled would-be voters waited in lines several hundred yards long for up to 18 hours without being able to vote. l

The breakdown of election machinery threw into serious doubt the credibility of the process which is intended to start the political rehabilitation of Uganda. Amin's eight-year reign of terror, during which half a million people were killed, was followed by three unelected governments in 18 months that have all vainly sought to stem the unending tide of violence.

One hour before the scheduled end of voting, the government-appointed election commission extended polling until Thursday afternoon, a move that threw into confusion many polling stations in the countryside where the election had gone relatively smoothly.

The commission ordered that vote-counting be delayed then, but monitors in the countryside reported that ballots were already being tallied in some stations before the order was issued.

Emmanuel Debrah, the head of the nine-nation Commonwealth observer team here to judge the elections, said he was "disgusted" by the administration of the polling in the capital area.

One of the observers for the Commonwealth, an organization of Britain and its former colonies, said, "the election commission is the most incompetent I've ever seen. After what this country has been through the people deserve better."

In one polling station in western Kampala, violence broke out when impatient backers of the Democratic Party beat an election agent of the rival Uganda People's Congress, led by Milton Obote who is favored to win the election. The party worker only reached safety when he was escorted through the hostile crowd by Western journalists, whom many of the Ugandans mistook for Commonwealth observers.

The Democratic Party supporters were mainly upset by alleged bribery of voters by a polling official who was turned over to the police. Later, the Ugandan Army moved in and closed the poll for the night, creating a tense situation. The party feels the military favors Obote.

In another area of western Kampala, Democratic Party members had an angry shouting march with election officials over alleged irregularities involving the locking of ballot boxes and their security.

All four parties contesting the election made charges of malpractice. After years of oppression and brutality, there is little trust between the rival political factions.

Despite the heated atmosphere and confusion, however, it was evident that a strong spirit of democracy was still alive among the people.

Tens and thousands of voters began lining up at the country's 5,000 polling stations as early as midnight, eight hours before the scheduled start of voting, and thousands more planned to stay there overnight without food, water or shelter to assure their right to vote Thursday. Many of the party faithful also stayed to try to assure that there would be no tampering with the polling process.

During a tense argument with polling officer Pius Lutumba in western Kampala, Daniel Kamanji gestured fiercely and shouted: "We are intelligent enough to understand our rights and we demand our rights. Today is our day. Maybe tomorrow they can threaten us."

Police finally moved to arrest Kamanji and some of his supporters. One of them, Ibrahim Nsubuga, shouted as he was leaving: "There is freedom of expression. We have suffered too long. We can't suffer simply because he [the policeman] has a gun."

There were fears with the mutual distrust between the supporters of the Uganda People's Congress and the Democratic Party there could be outbreaks of hostility during the night.

The rutted, charred downtown area of Kampala had an eerie sense about it today as the population deserted the capital to go home to constituencies to vote. The 10 p.m. curfew was lifted, a brief close-down of the country's main airport ended and the military lifted most roadblocks to facilitate voters going to the polls.

Ironically, Obote, who ruled the country from its independence in 1962 until he was overthrown by Amin in 1971, was also prevented from voting this morning, since his polling station had not received any ballots. He voted in the afternoon but charged that the officials were illegally seizing voter registration cards.