Ryan Routh, the man arrested in connection with an apparent attempt to assassinate former President Donald Trump Sunday, has a lengthy police record in North Carolina, built inexpensive houses in Hawaii and has a fixation with the war in Ukraine.

Routh, 58 years old, was detained by police in Florida after Secret Service agents spotted a man pointing a rifle through the fence at a West Palm Beach club where Trump was golfing and opened fire at him. The man fled in a black Nissan and was quickly apprehended.

Before his arrest, Routh had been seeking to recruit volunteers to fight in Ukraine, posting on social media about his willingness to fight Russia’s invasion and even traveling to Kyiv two years ago. He had lived through years of apparent turmoil, brushes with the law, and failed attempts to link himself to some larger purpose, according to public records, social-media posts and interviews with people who know him.

“I would tremendously enjoy the invitation to join any monumental worthy cause to bring about real change in our world,” Routh wrote in his LinkedIn profile. “I am certainly free to relocate to any remote location on the planet that might render the most positive impact.”

When Russia executed a full-scale invasion of Ukraine in early 2022, Routh appeared to find his cause.

On the day of the invasion he dispatched a series of tweets soliciting media coverage for his effort to encourage non-Ukrainians to travel to the country to take up arms, saying that he himself was ready to “fight and die” on behalf of Kyiv.

“We need to burn the Kremlin to the ground and put an end to Putin and Russia,” he wrote, referring to Russian President Vladimir Putin .

Routh arrived in Kyiv in April 2022. The city was largely deserted, and he sought connections with other Westerners who had come to lend a hand. He stood out, often wearing an American flag T-shirt or bandanna, according to people who knew him in Ukraine.

That April, he tweeted at the official account of Ukrainian President Volodymyr Zelensky , saying that he was in Kyiv and planned to erect a tent city in the capital to attract foreign fighters. “We can raise great support and equipment,” he wrote.

Routh tweeted a photo of himself in Kyiv’s Independence Square in front of a banner soliciting foreign volunteers and fighters.

“This conflict is definitely black and white,” Routh said in a 2022 interview with the Romanian version of Newsweek. “This is about good versus evil.”

He didn’t serve in the U.S. military, he told Newsweek’s Romanian outlet. In Ukraine, he was rejected from military service, according to two people who knew him there. Routh subsequently put his efforts into recruiting people to join Ukraine’s International Legion.

“That was his main task—that he assigned to himself,” said Chris Lutz, a German humanitarian volunteer who knew Routh in Ukraine. “He wasn’t officially assigned by the armed forces of Ukraine. It was just kind of his personal mission to do so.”

On Routh’s website, he wrote that “losing this war isn’t an option” and implored citizens around the world “to join this fight.” But in his discussions in Kyiv, Routh lacked clarity of thought and had trouble holding his audience, as he would leap from one topic to another.

“If you want to fight, come here and see me,” Routh said in the Newsweek interview. “And I’ll put you in a unit so you can go fight.”

“Ryan was more of a recruitment cheerleader,” Lutz said. “He became some sort of a mascot.”

Routh clashed with Ukraine’s International Legion, whose officials believed he was claiming an affiliation with the group. The legion didn’t immediately respond to a query about Routh’s involvement with the group.

Frustrated by his inability to penetrate military circles in Ukraine, Routh redirected his efforts to defense production and arms imports. He tried to make deals for drone production in Ukraine and made trips to neighboring countries, seeking to involve himself in discussions about arms exports, according to Johnny Rogers, an American who worked for a medical NGO in Ukraine.

“He went from wearing the American flag all the time, with crazy hair, to a suit,” Rogers said. “When he was in the suit mode, he was actively trying to get defense deals. He was trying every single angle he could to do military stuff. He wanted to be a player.”

In the spring of last year, he was meandering through the center of Kyiv deflated, out of energy and money, Rogers said.

Routh attended North Carolina Agricultural and Technical State University until 1998, studying mechanical engineering, according to his LinkedIn profile.

He contributed roughly $140 total to Democratic candidates in 2019 and 2020, federal data show, including $25 for former Rep. Beto O’Rourke (D., Texas) and $15 for long shot Democratic presidential hopeful Andrew Yang.

North Carolina records show that Routh had a long list of traffic misdemeanors. He pleaded guilty in North Carolina to larceny in 1997.

In 2002, Routh was convicted of possessing a weapon of mass destruction, according to North Carolina records. A story in Greensboro, N.C.’s News & Record said that Routh was apprehended with an automatic machine gun after a standoff with police.

Routh later relocated from North Carolina to Hawaii, where he built one-room shelters for as little as $4,500, according to his LinkedIn profile and a company website. But the outbreak of the war in Ukraine took him overseas.

Routh tried to recruit Afghan soldiers who had fled the Taliban to fight Russia, according to interviews and to a January 2023 New York Times article. Routh said that he planned to obtain Pakistani passports for the recruits and move them from that country and from Iran to Ukraine.

After returning to the U.S., he conceded in an interview outside the U.S. Capitol with the news site Semafor last year that his Ukrainian contacts, concerned about espionage, weren’t interested in Afghan volunteers.

Still looking for a cause, Routh shifted his focus to Taiwan, claiming on X last year that he could supply thousands of “economical NATO trained Afghan soldiers to help defend Taiwan” as part of a foreign defense force. There is no indication the idea went anywhere.

In a December post, Routh wrote that he could supply thousands of Afghan soldiers to work for the national police of Haiti.

Write to Brett Forrest at brett.forrest@wsj.com