The 2016 election was less than a month away, and Donald Trump's attorney had blown the deadline for paying Stormy Daniels to keep quiet about her alleged affair with the future president.

In an Oct. 17 email, an attorney for Daniels — a porn star whose real name is Stephanie Clifford — threatened to cancel the nondisclosure agreement by the end of the day.

That very morning, Trump's attorney, Michael Cohen, had created a limited liability company, public records show, that ultimately would serve as a vehicle for Daniels' payoff. But the money had not arrived. A second email to Cohen, a short time after the first, said Daniels was calling the deal off.

"Please be advised that my client deems her settlement agreement canceled and void," Daniels' lawyer, Keith Davidson, wrote in the email, which The Washington Post obtained.

Ten days later, the $130,000 payment arrived, according to another email reviewed by The Post. Daniels' story about her sexual encounter with Trump a decade earlier would remain under wraps long past Election Day.

The account of how the deal came together — and how it briefly fell apart — adds a dimension of brinkmanship to the public understanding of the transaction. On the day that Daniels canceled the deal, protesters gathered in front of Trump Tower in New York City to express outrage over week-old revelations that the Republican presidential nominee had once bragged about grabbing women by the crotch, news that was prompting a number of women to come forward with stories of alleged sexual misconduct by the candidate.

"The media is trying to rig the election by giving credence — and this is so true — by giving credence to false stories that have no validity and make it the front page," Trump told supporters that Oct. 17 night in Green Bay, Wisconsin. "They take a story with absolutely nothing, that didn't exist, and they put it in front-page news because they want to poison the minds of the voters."

Reached by phone late Friday, Cohen asked that questions be sent to him by email and then did not respond to them.

The White House and representatives of the Trump campaign did not respond to requests for comment.

The timing of the Oct. 27 payment, 13 days after the initial deadline and just 12 days before the election, could be significant. Two complaints filed with the Federal Election Commission argue that the payment was intended to influence the Nov. 8 election and violated campaign finance law because it was not reported as an in-kind donation.

In one complaint, the progressive research group American Bridge argues that had Trump been interested only in protecting his reputation, he could have secured Daniels' silence in 2011, when she first spoke with reporters about the alleged affair. Instead, the complaint says, Cohen waited until October 2016 — when Trump faced the prospect of a news story about his marital infidelity landing shortly before the election.

The second complaint was filed by Common Cause, a government watchdog group.

"The fact that this payment was made immediately before the presidential general election strongly supports Common Cause's claim that the payment was about the election and to influence the election," said Paul S. Ryan, vice president of policy and litigation at Common Cause.

Some campaign-finance experts see parallels to the case of former senator John Edwards, D-N.C., who was indicted by federal authorities in 2011 on charges that he used money from wealthy donors to hide an extramarital affair. The jury acquitted him on one charge and deadlocked on five other counts.

Cohen has denied violating campaign-finance law.

The Wall Street Journal first reported the payment to Daniels in January. The cancellation of the deal and the exact date of the payment have not been previously reported.

After the Journal published its story, Cohen initially dismissed reports of the payment as a "false narrative." He later issued a statement in which he said he "used my own personal funds to facilitate" a payment of $130,000 to Daniels. He said that neither the Trump Organization nor the Trump campaign was a party to the transaction and that neither had reimbursed him for the payment.

Gina Rodriguez, a representative for Daniels, did not respond Friday to messages seeking comment.

A spokesman for Davidson said he could not comment on client matters.

Two other FEC complaints focus on a reported $150,000 payment in August 2016 by American Media, publisher of the National Enquirer, to Karen McDougal, a former Playboy model who told the New Yorker that she had a nine-month affair with Trump.

Former AMI employees, speaking on the condition of anonymity, have told The Post that the company would routinely pay money to "catch and kill" stories about celebrities friendly with chairman and CEO David Pecker, and that he was close to Trump.

The complaints, filed by Common Cause and Free Speech for People, a group that seeks to limit corporate money in politics, argue that AMI paid to bury the story of Trump's infidelity and thereby influence the presidential election. The payment was made in coordination with the Trump campaign and constituted an illegal and unreported in-kind campaign contribution, according to the two complaints.

The White House has dismissed those allegations as "fake news."

In a statement, AMI called the claims "meritless."

"Despite the level of hysteria and partisanship in American politics, we are surprised and disappointed by the unprecedented attack on a media company by an organization that purports to value free speech," the company's statement said.

The FEC may launch an official investigation only if all four current commissioners — two Republicans, a Democrat and an independent — agree to do so. The commission does not comment on the status of any investigation until it has been resolved.

Daniels has said she met the future president at a celebrity golf tournament in Lake Tahoe in July 2006. He was a reality television star whose wife, Melania, had recently given birth to their son, Barron; she was a porn star working at a booth promoting Wicked Pictures, an adult-film company.

Daniels accepted an invitation from Trump to ride around the lakefront course in his golf cart.

"That was actually my first time on a golf course, and when you're riding around with Donald Trump in an Escalade golf cart during your first time out on a course, I'd say I was doing all right," she told Adult Video News, a trade publication.

Two other media outlets recently revealed that she had shared her account of a romantic relationship. Slate reported in January that in the months leading up to the 2016 election, Daniels had told the outlet about the affair and said she was paid in exchange for her silence. Years earlier, in May 2011, she gave a lengthy interview to In Touch magazine. Jordi Lippe-McGraw, the reporter who spoke with Daniels, told The Post that the transcript as published by the magazine last month accurately reflected the interview.

Citing former employees of the tabloid's publisher, the Associated Press has reported that In Touch killed the story after Cohen threatened to sue.

Blogger Nik Richie who runs a gossip site, thedirty.com, reported on Trump's alleged infidelity with Daniels in October 2011, five months after the In Touch interview. Daniels' lawyer later threatened him with a cease-and-desist order, Richie recently wrote.

The payment was routed through a bank account controlled by Davidson. Eleven months later, in September of 2017, the bank, City National Bank in Beverly Hills, asked Davidson about the source of the payment, according to an email reviewed by The Post. The reason for the bank's interest was not clear.

Bank officials declined to comment on whether the inquiry was provoked by a request or subpoena from law enforcement officials, was the result of a routine audit or came about for some other reason.

"As a matter of policy, we don't confirm or comment on inquiries from regulatory agencies or law enforcement, including subpoenas," read a statement from the bank.

Two House Democrats called Friday for an FBI investigation into the payments to Daniels and McDougal. In a letter, Reps. Ted Lieu, Calif., and Kathleen Rice, N.Y., both former prosecutors, described the payments as "evidence of moral failings by the President" and said they believed the transactions may have violated federal election law.