It was a showdown 25 years in the making: With the world itching to finally get a look at classified Kennedy assassination files, and the deadline for their release just hours away, intelligence officials were still angling for a way to keep their secrets. President Donald Trump, the one man able to block the release, did not appreciate their persistence. He did not intend to make this easy.

Like much else surrounding investigations of the 1963 killing of President John F. Kennedy, Thursday's release of 2,800 records from the JFK files was anything but smooth. It came together only at the last minute, with White House lawyers still fielding late-arriving requests for additional redactions in the morning and an irritated Trump continuing to resist signing off on the request, according to an account by two White House officials. They spoke only on condition of anonymity to discuss internal discussions.

The tale of the final hours before the congressionally mandated 25-year release deadline adds a new chapter to the story of Trump's troubled relationship with his spy agencies. He again flashed his skepticism and unpredictability in dealing with agencies long accustomed to a level of deference. Intelligence officials, meanwhile, were again left scratching their heads about a president whose impulses they cannot predict.

And those officials had their own story tell, some rejecting the notion they were slow to act on Trump's expectations for the documents. The CIA began work months ago to get its remaining assassination-related documents ready for release on Thursday, according to a person familiar with the process. The person, who was not authorized to publicly to discuss the process and spoke only on condition of anonymity, said the goal was to have all the agency's documents ready to be released in full or with national security redactions before the deadline.

Since taking office, Trump has challenged the integrity of intelligence leaders, moved to exert more control over U.S. spying agencies and accused his predecessor of using government spycraft to monitor his campaign. In the JFK files matter, one White House official said, Trump wanted to make clear he wouldn't be bullied by the agencies.

Whatever occurred in the lead-up to deadline day, Trump was irritated Thursday that agencies still were arguing for more redactions. The president earlier in the week had tweeted to tease the release of the documents, heightening the sense of drama on a subject that has sparked the imaginations of conspiracy theorists for decades. Under a 1992 law, all of the records related to the assassination were to be made public unless explicitly withheld by the president.

Just before the release Thursday, Trump wrote in a memorandum that he had "no choice" but to agree to requests from the CIA and FBI to keep thousands of documents secret because of the possibility that releasing the information could still harm national security. Two aides said Trump was upset by what he perceived to be overly broad secrecy requests, adding that the agencies had been explicitly warned about his expectation that redactions be kept to a minimum.

"The president and White House have been very clear with all agencies for weeks: They must be transparent and disclose all information possible," White House Principal Deputy Press Secretary Raj Shah said Friday.

Late last week, Trump received his first official briefing on the release in an Oval Office meeting that included Chief of Staff John Kelly, White House Counsel Don McGahn and National Security Council legal adviser John Eisenberg. Trump made it clear he was unsatisfied with the pace of declassification.

Trump's tweets, an official said, were meant as a signal to the intelligence community to take seriously his threats to release the documents in their entirety.

According to White House officials, Trump accepted that some of the records contained references to sensitive sources and methods used by the intelligence community and law enforcement and that declassification could harm American foreign policy interests. But after having the scope of the redactions presented to him, Trump told aides he did not believe them to be in the spirit of the law.

On Thursday, Trump's top aides presented him with an alternative to simply acquiescing to the agency requests: He could temporarily allow the redactions while ordering the agencies to launch a new comprehensive examination of the records still withheld or redacted in part. Trump accepted the suggestion, ordering that agencies be "extremely circumspect" about keeping the remaining documents secret at the end of the 180-day assessment.

"After strict consultation with General Kelly, the CIA and other agencies, I will be releasing ALL JFK files other than the names and addresses of any mentioned person who is still living," Trump wrote in a Friday tweet. "I am doing this for reasons of full disclosure, transparency and in order to put any and all conspiracy theories to rest."

Associated Press writer Deb Riechmann contributed to this report.