Thomas Brodnicki, 46, is to keep a distance of at least 100 yards from the 19-year-old Disney star, her house and place of work. Gomez's mother, stepfather and a household member have also been included in the protective order.
The judge found Brodnicki to be of substantial threat to Gomez.
Brodnicki even filed a declaration with the court, saying the restraining order should be issued. He said it's the only thing that will keep him away from Gomez.
Neither party was present in court during the ruling.
The restraining order comes despite another ruling by a different judge last November dismissing stalking charges against Brodnicki.
In October, Gomez wrote in a declaration that she was in extreme fear after learning that Brodnicki had threatened to kill her while he was on a psychiatric hold.
Prosecutors later alleged Brodnicki stalked the actress between July and October.