The cofounders of Reddit sold the company at age of 22.

The site was plagued by internet trolls and protesting users in the years that followed. Meanwhile, the cofounders' relationship faltered outside the office.

The pair went to therapy, mended their friendship, and returned to Reddit.

Today, it's one of the most widely read sites on the internet.

Alexis Ohanian and Steve Huffman were 22 years old when they sold Reddit, a popular online community, to publishing house Condé Nast for between $10 million and $20 million.

They sold it within two years of starting the company.

The pair shared the experience and the drama that followed during a live podcast taping of "How I Built This" with NPR's Guy Raz in San Francisco in August.

"This was 16 months of work that was going to mean more money for me than my entire family — my mother and father — had made in their entire lives," Ohanian told Raz on stage.

Reddit, the so-called "front page of the internet," is now valued at $1.8 billion. But before it became the eighth most popular site on the internet, Reddit nearly met an early end.

In the years following the site's sale, the company was almost taken over by by internet trolls. Users protesting internal issues at Reddit tried to shut the site down, and a revolving door of CEOs did little to stabilize the startup's reputation. Ohanian and Huffman, who took a hiatus from Reddit, were absent during much of that time. Meanwhile, their relationship soured.

Here's how the duo bounced back to save Reddit. (Check out the podcast for the full story.)

Ohanian and Huffman were friends before they were cofounders

The pair met on the first day of college — their dorm rooms were located across the hall from each other at University of Virginia — and played countless hours of PlayStation 2 over the years. As juniors, they hatched an idea for an app (not Reddit) and went into business together.

After a fateful meeting with investor Paul Graham over their spring break, they joined the inaugural class of Y Combinator, a tech startup accelerator, and set out to create Reddit.

An undated photo shows Alexis Ohanian (left) and Steve Huffman (third from left). Flickr/Chloe Rice

Reddit grew to become the 11th biggest site in the world with 70,000 unique visitors by 2006. When Ohanian and Huffman sold it that year to Condé Nast's parent company, Advance Publications, they joined the media giant as part of their contracts. For three years, they worked on a celebrity-gossip news aggregator, Lipstick.com, that used Reddit's underlying tech.

After eight years of living together, Huffman parted for San Francisco and Ohanian spent some time in Armenia, where his dad's family came from. Their friendship began to falter. They rarely spoke, about Reddit or their lives outside the office, they told NPR.

"When our contracts at Condé Nast expired, we kind of just said, 'Great, see you later," Ohanian said during the taping

"I didn't feel animosity, it was neglect," Huffman said.

They came together when Reddit needed them

In 2015, about five years since Ohanian and Huffman left Reddit, the company looked like it might go under. Internet trolls were spewing messages of hate across the site, and many moderators — users who supervise Reddit's thousands of forums — took their communities offline in protest of a key Reddit staffer's departure. The Southern Poverty Law Center pegged Reddit as an online bulletin board for the most violently racist content on the internet.

At the same time, Ohanian and Huffman started to repair their friendship.

"We never really exercised the muscles that founders have to exercise that best friends don't," Ohanian explained during the podcast. "It's great to be able to start a company with one of your best friends, but the conversations you have as cofounders are very different from the conversations you have as friends. We didn't have enough of the hard ones often enough."

The pair met for dinner in February 2015 and began to take inventory of the events and actions that caused their relationship to fall apart. They agreed at that first dinner to work on it.

"We actually saw my therapist [together]," Huffman told NPR.

Alexis Ohanian designed the mascot for Reddit, which is seen on display in the company's San Francisco offices. Robert Galbraith/Reuters

While they made strides in mending their friendship, operations at Reddit continued to unravel. Ellen Pao resigned as interim CEO in June 2015.

Ohanian served as a board member of Reddit at the time. He called Huffman for back-up.

"I remember my friends being like, 'Why are you running into that burning building?' And it just felt like, at the time, I had no choice. I really, really loved Reddit," Huffman told NPR. He said the computer engineer in him — not the CEO — believed he could fix Reddit's code and reclaim the site from trolls. Huffman was installed as the new permanent CEO in July 2015.

The number of employees at Reddit doubled in the year that followed, which helped Huffman address the company's myriad issues. Reddit improved a feature to block users and debuted a quarantine for offensive content, making it harder for people to find.

The company also launched Android and iOS apps, and within one year, more than half of the site's users viewed Reddit on mobile devices. Monthly unique visitors ballooned to 243 million.

Ohanian and Huffman remain close friends.