Alexei Gorinov, 60, was arrested in April after he was filmed criticising the invasion in a city council meeting.
Under the post-invasion law, anyone who spreads "fake news" about the military faces up to 15 years in jail.
Russians are banned from using the word war to describe the invasion.
President Vladimir Putin has instead coined the phrase "special military operation", although he spoke of the "war in the Donbas" in remarks to parliamentary leaders on Thursday.
Human rights activist Pavel Chikov said Gorinov's sentence was the first jail term under the new law. Until now judges have only handed down a fine or a suspended sentence.
Judge Olesya Mendeleyeva ruled he had carried out his crime "based on political hatred" and had misled Russians, prompting them to "feel anxiety and fear" about the military campaign.
Appearing in court in northern Moscow, Gorinov held up a piece of paper with words he had written in pen: "Do you still need this war?" A security official held up his hands to try to obscure the message.
The opposition councillor was arrested in late April, more than a month after he addressed a district meeting in the Krasnoselsky area of north-east Moscow.
At the meeting Gorinov objected to the idea of a children's drawing contest being held when children were dying in Ukraine. He had also tried to start the council meeting with a moment's silence to remember the victims.
Another opposition councillor who supported his remarks has since fled Russia. Prosecutors said they had both deliberately conspired to discredit the Russian military.
According to activists and reporters who were in court on Friday, Gorinov told the judge that Russia had exhausted its limit on wars in the 20th Century. "And yet its present is Bucha, Irpin, Hostomel," he said, listing some of the places where Russian forces are alleged to have committed war crimes.
His friend and opposition activist Ilya Yashin tweeted his "horror" at the sentence. Yashin himself was recently given a 15-day jail term for resisting arrest. Another activist, Maria Alyokhina, said it was "historic hell" that an elected councillor was being jailed for seven years for calling a war a war.
Russian political expert Tatiana Stanovaya said it was clear the authorities were sending a warning to "dissenters". Using the term war was sabotage in the eyes of the authorities, she said. But when combined with political action such as Gorinov's it was seen as almost terrorism and would be met with a long jail term.
Russian prosecutors are also calling for a long prison term for prominent pro-democracy figure Andrei Pivovarov, who was removed from a plane as it was about to leave St Petersburg in May. His lawyer said he was accused of directing an undesirable organisation, Open Russia.