Sofia Vergara and Joe Manganiello got a surprise house visit from a guy claiming to be a family friend -- except he was an uninvited stranger, so he got busted for trespassing ... law enforcement sources tell TMZ.
Our sources say the man managed to make his way into the gated community around noon last week where the Hollywood couple live, and was approached by security officers who grilled him.
We're told the guy said he was looking for Sofia's house and claimed to be friends with her son, Manolo.
Our sources say security felt something was fishy about the man's story so they contacted Joe ... who told them he didn't know the guy and he wasn't a family friend.
We're told security asked the man to leave the community but he allegedly refused, so cops were called to the scene. Our sources say the officers gave him one last chance to leave peacefully but he again refused ... so he was ultimately arrested and booked for trespassing.
It's unclear exactly how close he actually got to Sofia and Joe's home, but clearly ... too close for comfort.