The deaths on Wednesday come a week ahead of a presidential election.
A man, later described by police as an army reservist, opened fire on the crowd after supporters of Kizza Besigye, the opposition leader, accused him of being a security agent and pelted his car with stones, a Reuters witness said.
He was shooting out of the car window with an AK-47 automatic rifle as he drove away from the angry crowd outside a meeting Besigye was holding with cultural leaders. Besigye is President Yoweri Museveni's main rival in the election.
Military police fired teargas and live rounds in the air to disperse the gathering of thousands of opposition supporters.
Earlier in the day a judge ruled that the trial of Besigye should be adjourned until after the 23 February polls. Besigye's supporters say his treason charges are politically motivated.
Besigye left the meeting after the shooting at the centre of a crowd of hundreds of cheering supporters. Police said two people were killed and that the gunman - an army reservist working for a city official - was later arrested.
Besigye later attended a peaceful rally at nearby Makerere University, where he called for a moment of silence for the victims of the shooting. "This is the kind of regime that is once again unfolding in this country," he told the crowd.
Museveni is running for re-election to extend a 20-year rule his critics say has become increasingly autocratic.
He is favourite to win next week, with the latest poll giving him 50% of votes and 33% for Besigye. If neither man takes more than 50% on the day, a run-off will be held within a month.
Justice Vincent Kagaba ordered the trial to resume on 15 March after the prosecution said it needed time to respond to what the defence called "incurable" defects in the state's charges.
Besigye's Forum for Democratic Change (FDC) party says the charges are meant to sideline Besigye ahead of the polls, something the government denies.
The FDC leader is charged with treason along with 22 other men, and his lawyers objected to the indictment on several grounds, including that Besigye was accused of plotting to overthrow the government with unnamed individuals.
John Matovu, the defence lawyer, said the state must name the other suspects or concede it did not know their identities.
The judge should quash the charges, he added.
If Besigye wins the election, he would, as president, enjoy immunity from prosecution. But his lawyers say it is unclear what would happen to the trial before he is sworn in.