WASHINGTON — When a young American man from coastal Florida drove a truck packed with explosives into a hilltop restaurant in Syria in May 2014, F.B.I. agents scoured his online postings and interviewed his contacts in Florida in a scramble to determine who, if anyone, might try to launch a similar attack inside the United States.

One of the people they spoke to was Omar Mateen, a young security guard from a nearby town who had attended the same mosque as the suicide bomber and had been on a terrorism watch list for incendiary comments he once made to co-workers at a local courthouse. But the F.B.I. soon ended its examination of Mr. Mateen after finding no evidence that he posed a terrorist threat to his community.

That hopeful conclusion was upended in a bloody spasm of violence early Sunday morning when Mr. Mateen fatally shot dozens of people at a nightclub in Orlando, Fla., before being killed by police officers who stormed the club to end the standoff. The horrific events at the Pulse nightclub left 49 dead and have left family members, neighbors and federal investigators trying to piece together clues about what might have led Mr. Mateen, 29, to carry out such unspeakable violence.

The government investigation could take months, but an early examination of Mr. Mateen’s life reveals a hatred of gay people and a stew of contradictions. He was a man who could be charming, loved Afghan music and enjoyed dancing, but he was also violently abusive. Family members said he was not overly religious, but he was rigid and conservative in his view that his wife should remain mostly at home. The F.B.I. director said on Monday that Mr. Mateen had once claimed ties to both Al Qaeda and Hezbollah — two radical groups violently opposed to each other.

Investigators now face the question of how much the killings were the act of a deeply disturbed man, as his former wife and others described him, and how much he was driven by religious or political ideology. Whatever drove him to carry out the shootings, his actions highlight the difficulty for the American government in trying to address a new style of terrorism — random acts of violence that may have been at least partly inspired by the Islamic State but were not directed by the group’s leaders.

Unlike Al Qaeda, which favors highly organized and planned operations, the Islamic State has encouraged anyone to take up arms in its name, and uses a sophisticated campaign of social media to inspire future attacks by unstable individuals with little history of embracing radical Islam. President Obama said Monday that there was no evidence that the Islamic State actually directed Sunday’s attack, which would make Mr. Mateen’s case part of a pattern of domestic radicalization.