Whole Foods courted seven separate potential deal partners.

The company read a news story about Amazon's interest and reached out after feeling the heat from activist investors.

Amazon played hardball, demanding secrecy and nearly walking away after Whole Foods made a $45-per-share counteroffer.

The day that Amazon and Whole Foods announced their $13.7 billion merger that shook the grocery industry, a giddy John Mackey couldn't hide his enthusiasm.

The grocer's CEO regaled a crowd of his employees with a tale of "love at first sight," describing the moment the two companies met on a "blind date" six weeks earlier.

But in reality, the deal was far from inevitable, according to a Securities and Exchange Commission filing detailing how the merger went down.

In all, seven suitors were vying for Whole Foods. And though Amazon may have been the preferred deal partner, tough negotiations ensued, and the e-commerce behemoth came close to walking away from the deal.

Amazon arrived as a bidder in unusual fashion. Whole Foods read a news story from April suggesting the tech giant had been interested in acquiring Whole Foods but ultimately decided against it.

The organic-food retailer's management had since late 2016 been actively discussing strategies to improve Whole Foods' disappointing stock price, which had steadily declined along with profit in recent years.

Pressure to right the ship heightened in early April when the activist hedge fund Jana Partners announced it had acquired a nearly 9% stake in the company and was angling for a big shake-up in the top ranks.

Whole Foods' top brass had no desire to relinquish their control of the company without a fight, and a week later Mackey and his team hired a top defense banker from Evercore with more than a decade of experience battling activist and hostile investors.

Seven suitors

On April 18, inquiries started to trickle in. One industry competitor wrote a letter expressing interest in a deal, followed in subsequent days by inquiries from four private-equity firms.

That week, as interest from potential acquirers began to simmer, Whole Foods' management and an outside consultant mulled over a recent media report indicating Amazon had entertained the idea of buying up their company.

The Whole Foods consultant that Friday called Jay Carney, a former Obama administration spokesman who is now a senior vice president of corporate affairs for Amazon, to see if the tech giant might still be interested in pursuing the grocer. The next Monday, Amazon told the consultant it would be open to a meeting.

Meanwhile, pressure from Jana Partners intensified. That week, the hedge fund met with Whole Foods execs and made various demands, particularly insisting on an overhaul of the board of directors.

The Whole Foods board met that Friday, April 28, to discuss how it would respond to Jana. That's when Mackey informed members that he and other top executives were planning to jet off to Seattle to gauge Amazon's interest in acquiring the company.

They wasted little time, flying to Amazon's headquarters that Sunday for a meeting that Mackey later said lasted 2.5 hours and was "love at first sight."

"I think we coulda talked for 10 hours. And — when we huddled together, it was like we just had — we just had these big grins on our faces, like, 'These guys are amazing. They're so smart. They're so authentic,'" Mackey later told employees in a company town-hall meeting. "They say what's on their mind. They're not playin' a bunch of BS games. And it was like, 'This is gonna be so incredible.'"

But despite Mackey's optimism, a deal was far from certain, and Jana was breathing down his neck.

John Mackey Whole Foods More

Whole Foods tried to placate Jana the next week by offering up two board seats in exchange for the activist investor's retracting its claws and giving the company 18 months to pursue strategic measures to revive itself.

Jana declined the offer, but Whole Foods nonetheless shook up its board, appointing five new directors on May 10.

Story continues