ORLANDO, Fla. — A gunman who pledged allegiance to the Islamic State opened fire in a crowded gay nightclub here early Sunday in a shooting that left 50 dead and another 53 wounded. The gunman, identified as Omar Mateen, had been investigated twice by the F.B.I. for possible connections to terrorism, the bureau said, but no ties could be confirmed.
Mr. Mateen, 29, an American citizen whose parents were from Afghanistan, called 911 and talked about the Islamic State at the time of the massacre at the Pulse nightclub, the worst mass shooting in American history, Ronald Hopper, an assistant agent in charge of the F.B.I.’s Tampa Division, said at a news conference. Other federal officials said more explicitly that he had declared allegiance to the group.
“The F.B.I. first became aware of him in 2013 when he made inflammatory comments to co-workers alleging possible terrorist ties,” but could not find any incriminating evidence, Agent Hopper said.
Law enforcement officials said the suspect in the attack on an Orlando nightclub on Sunday had been monitored for possible terrorist ties, but was still legally able to buy guns.
In 2014, the bureau investigated Mr. Mateen again, for possible ties to Moner Mohammad Abusalha, an American who grew up in Florida but went to Syria to fight for an extremist group and detonated a suicide bomb. Agent Hopper said the bureau concluded that the contact between the two men had been minimal, and that Mr. Mateen “did not constitute a substantive threat at that time.”
The suspicions did not prevent Mr. Mateen, who lived in Fort Pierce, Fla., from working as a security guard, or from buying guns. The federal Bureau of Alcohol, Tobacco, Firearms and Explosives said Mr. Mateen legally bought a long gun and a pistol in the last week or two, though it was not clear whether those were the weapons used in the assault.
The gunman stormed the Pulse nightclub armed with an AR-15-style assault rifle and a handgun around 2 a.m., turning what had been a celebratory night of dancing to salsa and merengue music into a panicked scene of unimaginable slaughter, the floors slicked with blood, the dead and the injured piled atop one another.
Terrified people poured onto the darkened streets of the surrounding neighborhood, some carrying wounded and bleeding victims to safety; police vehicles were pressed into service as makeshift ambulances; and hundreds of people gathered at hospitals and on the fringes of the law enforcement cordon around the nightclub, hoping for some word on the fate of their relatives and friends.
“I saw bodies on the floor, people on the floor everywhere; it was a chaos, everybody trying to get out,” said Ray Rivera, a D.J. at the club who was playing reggae music on the patio area while Latin music played inside the building, when the shooting began. “I heard shots, so I lower the volume of the music to hear better because I wasn’t sure of what I just heard. I thought it was firecrackers, then I realized that someone is shooting at people in the club.”
Joel Figueroa and his friends “were dancing by the hip-hop area when I heard shots, bam, bam, bam, and the only thing I could think of was to duck, but I ran out instead,” he said. “Everybody was screaming and running toward the front door. I didn’t get to see the shooter.”
Some people who were trapped inside hid where they could, calling 911 or posting to social media, pleading for help. The club itself posted a stark message on its Facebook page: “Everyone get out of pulse and keep running.”
A three-hour standoff followed the initial assault, with people inside effectively held hostage until about 5 a.m., when law enforcement agencies led by a SWAT team raided the club in force, using armored vehicles and explosives designed to disorient and distract.
Hours after the attack, the Islamic State claimed responsibility in a statement released over an encrypted phone app used by the group. It stated that the attack “was carried out by an Islamic State fighter,” according to a transcript provided by the SITE Intelligence Group, which tracks jihadist propaganda.
But officials cautioned that even if Mr. Mateen, who court records show was born in New York and had been married and divorced, had been inspired by the group, there was no indication that it had trained or instructed him, or had any direct connection with him. The pair who killed 14 people in San Bernardino, Calif., in December also proclaimed allegiance to the Islamic State, but investigators do not believe they had any contact with the group.
“The F.B.I. is appropriately investigating this as an act of terror,” President Obama said from the White House. He said that the gunman clearly had been ”filled with hatred” and that investigators were seeking to determine any ties to overseas terrorist groups.
“In the face of hate and violence, we will love one another,” he said. “We will not give in to fear or turn against each other. Instead, we will stand united as Americans to protect our people and defend our nation, and to take action against those who threaten us.”
As he had after previous mass shootings, the president said the shooting demonstrated again the need for what he called “common sense” gun measures.
“This massacre is therefore a further reminder of how easy it is for someone to get their hands on a weapon that lets them shoot people in a school or a house of worship or a movie theater or a nightclub,” Mr. Obama said. “We have to decide if that’s the kind of country we want to be. To actively do nothing is a decision as well.”
The shooting was the worst terrorist attack on American soil since Sept. 11, 2001, and the deadliest attack in the nation’s history on a specifically gay gathering. The F.B.I. set up a hotline for tips.
Law enforcement officials increased security at gay pride events and gay landmarks in cities around the country, including Washington, New York and Chicago. Officials in Santa Monica, Calif., on Sunday confirmed the arrest of a heavily armed man who said he was in the area for West Hollywood’s gay pride parade. The authorities, however, said they did not know of any connection between the arrest and the Orlando shooting.
Some terrorist attacks, like the San Bernardino killings in December, have been carried out in the name of Islam by people, some of them born and raised in the West, who were “self-radicalized.”
The Islamic State in particular has encouraged “lone wolf” attacks in the West, a point reinforced recently by a spokesman for the group, Abu Muhammad al-Adnani, in his annual speech just before the holy month of Ramadan. In past years, the Islamic State and Al Qaeda ramped up attacks during Ramadan.
“Make it, Allah permitting, a month of hurt on the infidels everywhere,” Mr. Adnani said, according to a translation provided by the SITE Intelligence Group. Noting that some supporters have lamented that they cannot strike at military targets, he took pains to explain why killing civilians in the land of the infidel is not just permitted but encouraged.
Rasha Mubarak, the Orlando regional coordinator of the Council on American-Islamic Relations, released a statement saying: “We condemn this monstrous attack and offer our heartfelt condolences to the families and loved ones of all those killed or injured. The Muslim community joins our fellow Americans in repudiating anyone or any group that would claim to justify or excuse such an appalling act of violence.”
The toll of the dead and injured far exceeded those of the 2007 shooting at Virginia Tech, where 32 people were killed, and the 2012 shooting at an elementary school in Newtown, Conn., where 26 people were killed.
The club posted a message on its Facebook page about 3 a.m.: “Everyone get out of pulse and keep running.”
The Gay Lesbian, Bisexual, Transgender Community Center of Central Florida said it was offering grief counseling to victims and survivors.
Officials at Orlando Regional Medical Center asked members of the families of victims and missing people to gather at the north entrance, where they would be escorted inside.
The slaughter at Pulse occurred a day after the singer Christina Grimmie, a star of YouTube and the reality TV show “The Voice,” was shot down after a concert in Orlando. The police said she had been killed by a St. Petersburg, Fla., man who drove to Orlando with the specific intention to kill Ms. Grimmie. The man, Kevin James Loibl, killed himself moments later.
Chief Mina said Mr. Loibl had traveled to Orlando with two handguns, several loaded magazines and a hunting knife. Police officials were examining his telephone and computer to try to determine a motive.
Lizette Alvarez reported from Orlando, and Richard Pérez-Peña from New York. Reporting was contributed by Wendy Thompson and Les Neuhaus from Orlando; Alan Blinder in Fort Pierce, Fla.; Rukmini Callimachi from Paris; Eric Lichtblau and Eric Schmitt from Washington; and Steve Kenny, Richard A. Oppel Jr., Rick Rojas and Daniel Victor from New York