The order requires John Hobbs, 43, to stay away from the "How I Met Your Mother" actress and her family, and it orders him to stop posting messages about her online.
Hannigan states in her petition that in the past two months, Hobbs, a New Hampshire resident, has "posted a barrage of threatening messages directed at me and my family on various websites."
The actress wrote that she has never met Hobbs, but his messages have suggested he will rape her and take her to the "after-life." Hobbs recently was released from a mental hospital, according to the court filings.
"I am in severe fear for my safety and the safety of my family," she wrote.
Police in Hobbs' hometown of Nashua, N.H., contacted him and he acknowledged wanting to meet Hannigan, 38, and visit her in California.
"Hobbs seemed to be living in an alternate reality," the officer wrote after interviewing him and reviewing his Facebook account.
A phone number registered to Hobbs has been disconnected.
A hearing to extend the restraining order for three years is scheduled for March 6 in Los Angeles. The order also covers Hannigan's husband, Alexis Denisof, and their children, ages 1 and 3.
Hannigan rose to fame after appearing in the movie "American Pie." She also starred in "Buffy the Vampire Slayer."