ORLANDO — A gunman who pledged his allegiance to the Islamic State opened fire in a crowded gay nightclub here early Sunday, killing 50 people and injuring 53 others in the deadliest mass shooting in American history.
The gunman, identified as Omar Mateen, who was killed in an exchange of fire with police, had been investigated twice by the FBI for possible connections to terrorism but no ties could be confirmed, the bureau said.
Mateen, 29, a US citizen whose parents were from Afghanistan, called 911 during the massacre at the Pulse nightclub and talked about his loyalty to the Islamic State and mentioned the 2013 terrorist bombings in Boston, federal officials said.
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 jihadi propaganda.
But officials cautioned that even if Mateen had been inspired by the group, there was no indication that it had trained or instructed him, or had any direct connection with him. He apparently carried out the attack alone.
“The FBI 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, said Ronald Hopper, an assistant agent in charge of the FBI’s Tampa Division.
In 2014, the bureau investigated Mateen again, this time 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.
Hopper said the bureau concluded that the contact between the two men had been minimal and that Mateen “did not constitute a substantive threat at that time.” The suspicions did not prevent Mateen, who was born in New York and lived in Fort Pierce, Fla., from working as a security guard or from buying guns.
The gunman stormed the Pulse nightclub armed with an AR-15 semiautomatic rifle and a handgun about 2 a.m., just before closing, and fired more than 50 rounds toward the crowd of 300 people who packed the club.
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.
Thirty-nine of the dead were killed at the club, two bodies were found on the street, and 9 people died at hospitals, officials said. At least 53 people were hospitalized, most in critical condition, and a surgeon at Orlando Regional Medical Center said the death toll was likely to climb.
Two people in Western Massachusetts said they feared that a friend named Kimberly Morris was among the dead. Morris had performed at a club called Diva’s in Northampton and had recently moved to Orlando and worked as a bouncer at Pulse, said Holyoke city councilor Nelson Roman and Liz Mazzei.
The City of Orlando listed a 37-year-old Kimberly Morris as one of the shooting victims.
The rampage turned 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. 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.
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 posted a stark message on its Facebook page: “Everyone get out of pulse and keep running.”
“The FBI is appropriately investigating this as an act of terror,” President Obama said from the White House. He said the gunman clearly had been “filled with hatred” and that investigators were seeking to determine any ties to overseas terrorist groups.
As he had after previous mass shootings, the president said the shooting demonstrated again the need for “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,” 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 US soil since Sept. 11, 2001, and the deadliest attack in the nation’s history on a specifically gay gathering.
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 claims of a terrorist plot recalled the mass shooting of 14 people in San Bernardino, Calif., in December, in which a pair of attackers also proclaimed allegiance to the Islamic State but were not found to have had direct contact with the group.
Law enforcement officials increased security at gay pride events and gay landmarks in cities around the country Sunday, including Washington, New York, and Chicago.
Some terrorist attacks, such as the San Bernardino killings, have been carried out in the name of Islam by people, some 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 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,” 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.
The slaughter at Pulse occurred a day after singer Christina Grimmie, a star of the reality show “The Voice,” was killed after a concert in Orlando.
Aimee Ortiz of the Globe staff contributed to this report.