EXCLUSIVE

"How I Met Your Mother" star Josh Radnor has been ordered by a judge to stay 7 yards away from his next door neighbors -- seriously -- after the neighbors claimed Josh was making their lives miserable.

It all started over a gigantic deck Josh built on his property that extended over the neighbor's land. Josh has an easement over the area where he built the deck, but the family next door has filed a lawsuit claiming he had no right to build the deck in the first place.

The family got permission from the city to tear it down because apparently Josh didn't get the necessary permits. Josh went to court and got a judge to block the neighbors from destroying the deck.

That said, the family next door tells TMZ, Josh and his roommate scream at them every time they go outside. The neighbors say Josh and his roommate take pics of them and rail on them. They also claim Josh intimidates any workers who come onto the family's property.

For some reason, the neighbor has a problem that Josh sometimes comes out shirtless.

Whatever ... the family just got a temporary restraining order, requiring Josh to stay 7 yards away from them when they're at home. He also can't harass or intimidate them.