WASHINGTON — In the hours before his arrest, as federal authorities zeroed in and secretly accumulated evidence, Cesar Sayoc was in his element: spinning classic and Top 40 hits in a nightclub where he’d found work as a DJ.

As he entertained patrons from a dimly lit booth overlooking a stage at the Ultra Gentlemen’s Club, where Halloween decorations hung in anticipation of a costume party, he could not have known that investigators that very evening were capitalizing on his own mistakes to build a case against him.

In the end, prosecutors who charged Sayoc with five federal crimes Friday say the fervent supporter of President Donald Trump unwittingly left behind a wealth of clues, affording them a critical break in a coast-to-coast investigation into pipe bomb mailings that spread fear of election-season violence. The bubble-wrapped manila envelopes, addressed to Democrats such as Barack Obama and Hillary Clinton and intercepted from Delaware to California, held vital forensic evidence that investigators say they leveraged to arrest Sayoc four days after the investigation started.

“Criminals make mistakes so the more opportunities that law enforcement has to detect them, the greater chance they’re going to be able to act on that, and that appears to be what happened here,” said former Justice Department prosecutor Aloke Chakravarty, who prosecuted the Boston Marathon bombing case.

But it wasn’t always clear that such a break would come, at least not on Monday when the first package arrived: a pipe bomb delivered via mail to an estate in Bedford, New York, belonging to billionaire liberal activist George Soros. That same day, Sayoc, still under the radar of law enforcement, retweeted a post saying, “The world is waking up to the horrors of George Soros.”

Additional packages followed, delivered the next day for Clinton and Obama and after that to the cable network CNN, former Attorney General Eric Holder, former Vice President Joe Biden and other Democratic targets of conservative ire.

Each additional delivery created more unease. But together they also provided more leads for the FBI, which mined each pipe bomb for clues at a laboratory in Quantico, Virginia.

As the packages rolled in, technicians hit a breakthrough: a fingerprint and DNA left on a package sent to Rep. Maxine Waters, a California Democrat and one of the intended pipe bomb recipients, and DNA on a piece of pipe bomb intended for Obama. The FBI said it had identified no other possible matches on the evidence it had examined.

Besides that, the FBI said, his social media posts that traffic in online conspiracy theories, parody accounts and name-calling include some of the same misspellings as were noticed on the 13 packages he was charged with sending.

The clues, authorities say, led them to a 56-year-old man with a long criminal history who’d previously filed for bankruptcy and appeared to be living in his van, showering on the beach or at a local fitness center.

As the FBI worked around the clock, and as Americans were busy debating the hard-edged political climate and whether Trump had fanned the flames with his rhetoric, it was business as usual for Sayoc as he took to Twitter to denigrate targets like Soros. That was not uncommon for the amateur body builder and former stripper whose social media accounts are peppered with memes supporting Trump and posts vilifying Democrats.

On Thursday from noon to 9 p.m. as law enforcement grew ever closer, descending on a postal sorting facility in Opa-locka, Florida, Sayoc was working as a disc jockey at a West Palm Beach nightclub where he’d found work in the last two months. There, he spun his music from inside a small dimly lit booth overlooking a stage with performers dancing below. Autographed photos of scantily clad and nude adult entertainers were plastered across the walls like wallpaper.

“I didn’t know this guy was mad crazy like this,” said Stacy Saccal, the club’s manager. “Never once did he speak politics. This is a bar. We don’t talk politics or religion in a bar, you know?”

But Scott Meigs, another DJ at the club, had a different experience.

He said Sayoc had been talking about politics to everybody at the club for the last two weeks, preaching the need to elect Republicans during the November elections. “I just figured he was passionate about the upcoming elections.”

The next morning, he was taken into custody near an auto parts store in Plantation, Florida, north of Miami. Across the street, Thomas Fiori, a former federal law enforcement officer, said he saw about 50 armed officers swarm a man standing outside a white van with windows plastered with stickers supporting Trump and criticizing media outlets including CNN.

They ordered him to the ground, Fiori said, and he did not resist.

“He had that look of, ‘I’m done, I surrender,’” Fiori said.

Associated Press writers Laurie Kellman, Ken Thomas, Jill Colvin, Michael Biesecker, Stephen Braun and Chad Day in Washington; Ellis Rua, Terry Spencer, Kelli Kennedy and Curt Anderson in Florida; Jim Mustian, Deepti Hajela, Tom Hays and Michael R. Sisak in New York; and Raphael Satter in Paris contributed to this report.