At Overstock.com’s 20th-anniversary party last month, employees played tug-of-war, munched on artisan pickles and scrambled through an inflatable obstacle course at the company’s headquarters near Salt Lake City. It was a celebratory affair, complete with a reggae band, but for founder and chief executive Patrick Byrne, it held a tinge of melancholy.

He was about to resign, and not exactly by choice.

The retailer’s chief financial officer had just informed the board of directors that Overstock could not renew its insurance policy as long as Byrne was in charge. The CEO’s incessant broadcasting of his involvement in a “deep state” investigation had irreparably linked his personal life with the public company. On Overstock letterhead the week before, he claimed that he had romanced a Russian agent at the urging of the “Men in Black” — his term for federal agents — and effectively inserted himself into an international political scandal.

Now Overstock’s insurance provider had concerns about the company’s ability to “manage the CEO’s personality and public comments,” according to internal emails obtained by The Washington Post.

In his Aug. 22 resignation letter, dated two days after the anniversary party, Byrne said he’d become ensnared in “certain government matters” and that his “rabbi,” Warren Buffett, had advised him to come clean to the American people. Later that day, Byrne appeared on Fox Business wearing a “Make America Grateful Again” hat and claimed a federal agent had offered him $1 billion to keep quiet.

But he was obligated to come forward because, he told Fox, “This country’s gone nuts."

Byrne’s resignation capped an unconventional and controversial two-decade run at Overstock.com, a billion-dollar retailer best known for moderately priced home goods. But the company that revolutionized furniture-buying to become one of the biggest successes in e-commerce was now reeling from a series of missteps and diversions, leaving it with hundreds of millions of dollars in annual losses. The company’s flagship site had become an afterthought for Byrne, 56, who wanted desperately to sell it to focus on his cryptocurrency businesses.

But perhaps the biggest bombshell was Byrne’s claims of entanglement with the FBI. In a corporate news release last month, Byrne said he had been assisting federal agents in their investigation of Russian election interference through his three-year relationship with Maria Butina, the accused Russian agent.

Overstock shares fell 36 percent within days of the news release as anxious investors absorbed Byrne’s accounts of political intrigue, espionage and, in his words, a “handful of trysts” with Butina. The board was losing patience, and its chair, Allison Abraham, had begun forwarding hate mail to him, he said. Abraham did not respond to a request for comment.

Soon Overstock’s insurance carrier was expressing reservations about renewing its liability plan for directors and officers, a scenario that corporate insurance experts say is highly unusual.

“I’ve heard of companies that are too toxic to touch, but for one individual to be a liability risk for the whole company? That’s pretty extraordinary,” said Dan Bailey, an Ohio-based lawyer who has been drafting such policies for more than 30 years. “I don’t think I’ve ever seen that before.”

Internally, executives explored whether they could get a policy that covered all directors and officers except Byrne. When it became clear they couldn’t, Byrne says, he knew it was time to walk away.

“I figured that when one is having to parse finely what ‘impossible’ means when it comes to getting insurance, it was time to leave,” said Byrne, who spoke to The Post by phone and through more than 80 emails over three weeks.

***

Overstock was designed to keep its shoppers guessing.

The site began as an online flea market where wholesalers could offload just about anything, including exercise machines, bedsheets and Star Wars figurines.

The company got its start in 1999, at the height of the dot-com boom, when Byrne took a $7 million stake in D2: Discounts Direct, an online outlet for excess inventory and relaunched it under the new banner. It grew rapidly: Annual revenue catapulted from $1.8 million in 1999 to $25.5 million in 2000. By 2002, the company saw $92 million in revenue and turned its first quarterly profit.

“In many ways, Overstock revolutionized e-commerce,” said Stormy Simon, who started working for the company in 2001 and was its president from 2013 to 2016. “We were the first to ship couches and huge rugs across the country. There wasn’t a lot of competition — it was just us, Amazon and eBay."

Many of the company’s early practices have become standard in online shopping. Overstock was a pioneer in “drop shipping,” in which companies cut out the middleman by allowing third-party vendors to ship directly to customers. Meanwhile, its Club O membership program — introduced in 2004, a year before Amazon Prime — allowed shoppers to pay a flat fee for a year’s worth of free shipping. (Jeff Bezos, the founder and chief executive of Amazon, owns The Post.)

By the mid-2000s, though, new competitors emerged. Overstock moved to improve efficiency and invested heavily in updating its computer systems. But it ended 2005 with $25 million in the red. A year later, losses widened to $97 million.

Its stock also was in free fall, shedding about 80 percent of its value from 2005 to 2007. Byrne attributed that decline to systematic problems on Wall Street, including naked short-selling, in which investors bet against a company’s stock without having borrowed shares. It was all part of a wide-ranging Wall Street scheme, he told investors in a 2005 conference call, that involved “miscreant” hedge funds, high-profile journalists and the SEC. He claimed someone called “the Easter Bunny” had clued him in on the conspiracy, and that it was being overseen by a “Sith Lord,” a reference to a Star Wars villain. (In later interviews, he compared the network of “miscreants” to al-Qaeda.) Although the comments raised eyebrows, the company’s board made no public effort to rein him in.

“I listened to that conference call with my jaw on the floor,” said a former executive who spoke on the condition of anonymity to discuss internal affairs. “But of course nobody pushed back. Everyone was working for Patrick. It was his company, and that was it.”

Byrne became more outspoken over time and sought a bigger platform. He started a website, DeepCapture.com, where he laid out his views and frequently took aim at former colleagues, journalists and hedge fund managers. (In a recent high-profile libel suit, a Canadian judge ordered Byrne and his site to pay nearly $1 million to a Vancouver businessman after DeepCapture accused him of being an arms dealer and terrorist.)

But the campaign also drove his multimillionaire father, John Byrne, to resign from Overstock’s board. The man widely credited with rescuing Geico from bankruptcy in the 1970s said at the time that he disagreed with his son’s “jihad” against Wall Street. (He rejoined the board four years later, saying his son had been “right all along.”)

“It became all about, ‘I’m going to take down Wall Street,' and that became more important than the business,” said Simon, the former president. “Patrick just didn’t love retail after that."

In 2007, Byrne sued nearly a dozen major Wall Street banks, including Goldman Sachs and Morgan Stanley, for $3.5 billion, alleging that a “massive, illegal stock market manipulation scheme” had driven down Overstock’s share price. Several of the banks settled out of court in 2010, for a collective $4.4 million. Merrill Lynch’s case extended into 2016, when it agreed to a $20 million settlement. (He also collected a $5 million settlement from Rocker Partners, a hedge fund he claimed was manipulating the company’s stock.)

“The lawsuits ended successfully,” a spokesman for Overstock said. “And the regulatory changes advocated by Overstock lessened the debilitating consequences of the 2008 financial crisis to some of the largest banks in this county.” That same year, the Securities and Exchange Commission banned “abusive naked short selling.”

Byrne said he personally bankrolled the $30 million for his “mitzvah with Wall Street,” which former employees say began taking priority over the company. “The oligarchy picked a fight; I clubbed them like a little baby seal,” he said in an email. “It was an honor to be able to put that wealth to such good purpose.”

Byrne’s deep distrust of Wall Street lingered. Until a few years ago, the company kept $10 million in gold and silver coins, along with enough food to feed its employees for three months (the stockpile is now down to a few weeks). “Why? To make our firm robust in the face of a number of social ills that could beset our nation,” Byrne said in an email to The Post.

The company also invested heavily in blockchain, the technology behind digital cryptocurrencies. It began accepting bitcoin in 2014, making it the first mainstream retailer to do so, and has continued to pour hundreds of millions of dollars into Medici Ventures, its blockchain investment business, and tZero, its trading platform for digital coins. (That part of the business has been the subject of a years-long investigation by the SEC, though executives have said there has been no indication the agency plans to pursue legal action. The SEC declined to comment.)

Byrne has long confounded those around him. He has a doctorate in philosophy from Stanford University and a black belt in taekwondo. Much of his world view, he has said, was shaped by three bouts with cancer, starting with a diagnosis of testicular cancer in his early 20s.

Internally, Byrne was known for having grandiose plans and a short attention span, according to interviews with former employees and executives, and one former board member who spoke on the condition of anonymity to discuss the company candidly. Byrne relied heavily on an insular group of executives who referred to themselves as “coyotes” and rarely challenged his views, several of them said.

Byrne left his mark on every part of the company: Its newest headquarters was designed to look like a peace sign from above, and like a “corporate version” of the Roman Colosseum from ground level, according to a company release. He also helped create an internal voting system that allowed employees to weigh in on company decisions, such as whether Snoop Dogg should perform at the office or who should be fired.

In recent years, Byrne had been trying to sell Overstock’s retail business, setting up meetings with Walmart, Target, Home Depot and the furniture rental company Aaron’s, according to a person involved in the discussions who spoke on the condition of anonymity because the talks were not public. Representatives for the four retailers declined to comment, as did Overstock.

Byrne said he had hoped to sell the retail business in an auction scheduled for March 8, 2018. But days earlier, the company disclosed that the SEC was investigating its blockchain business. Almost immediately, “everybody backed out,” Byrne said, and the company was forced to put its plans on hold. Overstock has yet to find a buyer.

Meanwhile, Byrne doubled down on bitcoin, pouring his ambitions and money into blockchain technology and start-ups — which is what led him to Maria Butina.

***

Their story began at Planet Hollywood in Las Vegas.

It was 2015, and Byrne had just given a speech about cryptocurrency at FreedomFest, an annual meeting of libertarians that attracted such speakers as Donald Trump, Steve Forbes and Peter Thiel. He said he quickly noticed a “striking redheaded young woman” waiting to speak with him.

Butina introduced herself as the president of a gun rights group in Russia and handed him her business card, Byrne wrote on DeepCapture.com. The next day, she approached him again, with a different card. This one identified her as a special assistant to the vice chairman of the Central Bank of Russia. “Dr. Byrne, please allow me to tell you why I am really here,” she said, according to Byrne. “I have been sent here to make contact with you."

Butina’s attorney, Robert Driscoll, disputes Byrne’s version of events: “She wasn’t sent to the U.S. by anybody, and she certainly wasn’t sent to the U.S. to make contact with Patrick,” he said, though he confirmed that the two had a romantic relationship.

Byrne invited Butina to his hotel suite for a lunch meeting. Butina told him she was being groomed to become the next president of Russia, Byrne said, and invited him to Moscow to speak about bitcoin at the Russian Central Bank.

Byrne said he then contacted federal authorities and asked whether it would be okay to accept Butina’s invitation to Russia. It took weeks, he said, to get an answer but eventually he received a “green light” telling him to move forward. He had no expectation that their relationship would turn romantic, but Butina “swept me and my liberalism off my feet,” he wrote on Deep Capture. A spokeswoman for the FBI declined to comment.

He said they spent a weekend together in New York, then met up every so often in different parts of the country. It reminded him of “Lost in Translation,” he said, referring to the 2003 film in which an aging actor played by Bill Murray and a recent college graduate played by Scarlett Johansson have a series of intimate meetings.

“We had a handful of trysts like that,” he told The Post in an email, “spread across time, in the background of the normal narrative arc of her life.”

In late 2015, he said, Butina told him she’d been given orders to make contact with the presidential campaigns of Hillary Clinton, Donald Trump, Marco Rubio and Ted Cruz. (Driscoll disputes this.) Byrne said he reported this to “the Men in Black.”

Two former FBI special agents deemed the claims improbable. It’s unlikely, they said, that a highly trained foreign agent would have revealed her targets — in this case, as Byrne says, the four political campaigns — or that the FBI would have approved a romantic relationship as a means to collect intelligence.

They also dismissed Byrne’s claims that his 2015 phone calls helped spearhead the massive investigation into Russian election interference that culminated in a sprawling, $32 million inquiry by special counsel Robert S. Mueller III. Byrne said he was never contacted by Mueller’s team.

“There are a lot of steps it seems he’s not aware of,” said John Iannarelli, a retired FBI special agent, who called Byrne’s claims “ridiculous.” “Nothing he has said indicates that he understands how procedures operate.”

When asked why Butina might have revealed her alleged orders, Byrne said she did so while she was “heavily ‘under the influence’” of “large quantities” of serotonin, oxytocin and dopamine — the brain chemicals that spark feelings of love and attraction.

Byrne claims his history with the FBI dates back to 2002, when his friend and former NBA player Bison Dele disappeared in the Pacific Ocean. Byrne wrote on Deep Capture that he had a “minor involvement in helping the authorities sort it out.” (Dele has never been found; authorities believe he and two others were killed by his brother.)

As for Butina, Byrne said that he was under the impression he was receiving orders from top FBI officials. Six months into the relationship, Byrne said, the bureau asked him to break up with her. And he did — by text.

Soon though, Byrne says, the “Men in Black” returned with another request: “They wanted to ask me to rekindle a romantic relationship with Maria Butina,” he wrote on DeepCapture. “Russia was trying to subvert our election, and I was to get to the bottom of Maria Butina. ‘Gloves off.’”

Byrne says he obliged, setting off a chain of events that led to his departure.

***

Byrne is out — but the turmoil at Overstock remains.

On Monday, the company revised down its earnings forecast for the year — in part because of “significantly” higher insurance costs for directors and officers — and announced that its chief financial officer had resigned. Its share price has tumbled about 20 percent this week.

Former employees say Overstock’s retail site has become overly dependent on sweeping discounts and antiquated ideas. They expressed doubts that the new CEO, Jonathan Johnson, a company veteran who most recently led Overstock’s blockchain arm, would be able to steer the business in a new direction.

“I’ve been shoulder-to-shoulder with Patrick for 17 years,” Johnson, who unsuccessfully ran for governor of Utah as a Republican in 2016, said in an interview. “If Patrick’s the architect, I’m the builder.”

In practical terms, Johnson says, that means Overstock.com — synonymous for many with bed frames and bath towels — could soon become solely a blockchain company. “If the right fit comes along at the right price, well, we could find another home for retail,” he said.

The company’s e-commerce business has faced mounting competition in recent years, not just from rival websites, but also more traditional retailers like Walmart and Target that are doubling down on home goods and furniture. Overstock’s largest competitor — and the one that seemed to most vex its executives — was Wayfair, a company that regularly posts hundreds of millions of dollars in annual losses but has attracted large-scale venture capital funding and has eclipsed Overstock in revenue and market share. Last year, Wayfair posted a loss of $504 million, more than double Overstock’s $218 million loss.

Wayfair’s growing market share, former executives said, was a frequent source of tension within Overstock. And although Byrne’s departure may have helped the e-commerce giant insure its executives in the short term, they say they’re still worried about the company’s long-term prospects.

“You look at it now, and the retail business just isn’t loved anymore,” Simon said. “If you’re not going to feed the baby, you should at least give it up for adoption.”

***

Byrne is now on an island in Asia, he says, waiting for the whole thing to blow over. He says he has a duty to distance himself — both physically and financially — from the company he started 20 years ago.

He has gold and silver reserves in Switzerland, though he is becoming worried about “the deteriorating world situation.” Last week he sold his entire stake in Overstock — worth $90 million — and is reinvesting some of it in gold, silver and two types of cryptocurrencies, to shield his fortune from “acts of retaliation from the Deep State.”

“That is important because, in fact, I am now going to shellac them,” he wrote on his blog. “Actually, ‘shellac’ is too weak a word for what I intend to do to the Deep State. Sit back and enjoy the show.”

Correction: A previous version of this article misstated the wealth of Patrick Byrne’s father, John Byrne. John Byrne was worth $400 million at his death in 2013, according to his son.