In a ruling on a petition filed by a rights activist seeking the quashing of that section of the law, the Constitutional Court agreed, saying it violated the constitution.
Constitutional Court Judge Kenneth Kakuru, who wrote the lead judgment on behalf of a panel of five judges, said that section of the law "is unjustifiable as it curtails the freedom of speech in a free and democratic society."
He declared it "null and void" and banned its enforcement.
Under Uganda's Computer Misuse Act, one of the sections proscribes the use of electronic communication to "disturb the peace, quiet or right of privacy of any person with no purpose of legitimate communication".
Punishments for offenders can range from steep cash penalties to jail sentences of several years.
Critics say the laws are indiscriminately broad, disguised censorship and that they have mostly been used to punish opponents of Museveni, who has ruled Uganda since 1986.
Stella Nyanzi, a university lecturer and author who earned a huge social media following for her profanity and vulgarity-laced criticism attacks on Museveni, spent more than a year in jail after she was convicted under Uganda's electronic communications laws.
She subsequently fled Uganda and now lives in exile in Germany alongside another Ugandan author and international award winner, Kakwenza Rukirabashaija, who was also prosecuted under the same laws before he also fled.
There was no immediate response from government spokesman Ofwono Opondo to a Reuters request for comment.