Prosecutors had requested the former comedian be put behind bars for nine months for breaking into a sealed-off hut near a highly-contested high speed train line between France and Italy.
Nine activists of the No TAV movement - accused of entering the hut with Grillo - were given sentences of up to nine months, while 10 other suspects were found not guilty.
"Today they sentenced me to four months. I will not give up. Your solidarity really helps," Grillo wrote to his supporters on Twitter.
The outspoken leader, whose M5S party took a quarter of the votes at last year's national election, has admitted entering the hut but says there was no seal to break.
His lawyer and nephew, Enrico Grillo, said they would wait to read the court's explanation of the verdict before deciding whether to appeal or not.
No TAV head Alberto Perino, who also received four months in prison, said that "a sentence this severe for a crime of this type is unique in Italy".
"It well illustrates the climate of witch-hunting that exists," he said.
In January, three members of the movement against the high-speed train line were ordered by a court to pay close to €200,000 in damages for blocking construction work.
Launched in 2001, the rail link is meant to halve travel times between Lyon and Turin and cut the Paris-Milan journey from seven hours to four, while taking a million trucks off the road and averting three million tonnes of greenhouse gas emissions per year.
But the €26-billion project has faced fierce, sometimes violent opposition in Italy from environmentalists and affected residents who say it is wasteful and unnecessary.
It is also running behind schedule, its start date pushed back to 2025 at the earliest.