Sonja Morgan had to call an ex-FBI agent to protect her home after she accidentally invited nearly 1,000 people to an intimate cocktail party.

Morgan told us that she came home late from an event to send out a Paperless Post invite for a small gathering of around 30 close friends visiting from Europe, “plus a couple of hairdressers,” but found that the service — which she has used before — wouldn’t work.

“So I started sending them individually, and all of a sudden it says, ‘580 sent, 720 sent, 960 sent,’ ” Morgan tells us. “My friend called in two minutes and said, ‘Shall I come over? Are you hyperventilating?’ ”

She says the message went out to everyone, including staff at her parking garage, her kids’ teachers, a catering service she’s used in the past and even Page Six. Morgan says rumors quickly spread that she was hosting a grand masquerade ball and that at least one “Real Housewives” co-star reached out to her and insisted on attending.

The Bravo star says she quickly called a pal who used to serve in the FBI, who came to act as a bouncer in case a multitude arrived expecting canapes and martinis, and she sent out a series of emails explaining the gaffe and encouraging people to not show up, adding that she hoped they could come another time.

A message read, “So sorry to let you know my Paperless Post has gone haywire . . . It sent invites to my entire list for a small cocktail I am having for some friends in my small garden tomorrow.” She added, “Please disregard if you received tonight.”

In the end, only three unintentionally invited people arrived and all left with good humor.