ORLANDO — The heavily armed assailant who killed 50 people in a packed nightclub early Sunday in the deadliest shooting spree in U.S. history pledged allegiance to the Islamic State before he was killed in a hail of gunfire, authorities said.

Federal authorities identified the shooter as Omar Mateen, 29, a New York-born resident of Fort Pierce, Fla., who worked for the security firm G4S.

FBI special agent Ronald Hopper said Mateen made allusions to the Islamic State in a communication with law enforcement before he was killed by police. Hopper said agents had investigated Mateen in 2013 and again in 2014 regarding terror threats, but lacked sufficient evidence in both cases to pursue charges.

Orlando Mayor Buddy Dyer said another 53 people were wounded at Pulse Orlando, a gay club just south of downtown.

"Tonight our community witnessed a horrific crime... that will have a lasting effect on our community," a solemn Dyer said. "We will not be defined by a hateful shooter. We will be defined by how we love each other.”

President Obama called the massacre "an attack of terror and an attack of hate."

RELATED | NBC sources: Orlando nightclub shooter called 911 to pledge allegiance to ISIS

Orlando Police Chief John Mina said the tragedy began unfolding at 2:02 a.m., when three police officers engaged the suspect in a gun battle outside the club. A hostage situation then took place inside, and a SWAT team was called in, Mina said. Police received updates from patrons trapped in the club, and decided to storm the club at about 5 a.m.

"Our biggest concern was further loss of life," he said. "We exchanged gunfire with the suspect, and he was dead at the scene."

Eleven officers were involved in the final shootout, Mina said.

Mina said the gunman was armed with an assault rifle, a handgun and some sort of unidentified device. The Bureau of Alcohol, Tobacco, Firearms and Explosives said Mateen bought guns legally within the last few days.

Mina initially estimated the death toll at more than 20 people. Hours later the true scale of the horror was revealed. Mina said one officer was wounded and at least 30 people were rescued.

City Commissioner Patty Sheehan said the club had an armed officer at the door when the assault began, but that "there is only so much you can do."

The suspect's father, Mir Seddique Mateen, told NBC News on Sunday that he was shocked by the news, but that his son had recently expressed anti-gay sentiments. The father said the attack "had nothing to do with religion."

G4S issued a statement expressing shock and sadness at the "unspeakable tragedy." The firm said Mateen had been employed since September 10, 2007, and that G4S was cooperating fully with the investigation.

Supporters of the Islamic State, the extremist group that seized parts of Syria and Iraq, lauded the attack on social media. The militants' news agency, Amaq, said the attack was carried out by an Islamic State fighter. It was not clear, however, if Islamic State leaders had any prior knowledge of the attack.

Obama, in a brief speech to the nation, said the crime shows once again how easy it is for someone to get a weapon for use in a mass killing. He also expressed condolences to the families of the victims. The White House said Obama was getting updates on the case from Homeland Security.

"The place where they were attacked was more than a nightclub, it was a place of solidarity, empowerment, where people come together to raise awareness," he said.

Gov. Rick Scott declared a state of emergency for Orange County. "You don't want this to happen anywhere in the world," Scott said. "It's devastating when you see how many people lost their lives and the impact on the families."

Muhammad Musri, president of the Islamic Society of Central Florida, thanked law enforcement officials for their efforts and cautioned against any rush to judgment because the alleged killer was a Muslim, according to media reports.

"No one could have expected this, no one could have prepared for it, it could have happened anywhere," a visibly shaken Musri said at a news conference. "It's like lightening."

He said the city and Muslim community "are heartbroken."

Club owner Barbara Poma said she was "devastated" and expressed condolences to all who lost loved one.

Many of the casualties were rushed to Orlando Regional Medical Center, which was placed on lockdown. The process of identifying the victims and notifying families was underway, and a city website was slowly compiling the names of the victims. Among the first released: Edward Sotomayor Jr., Stanley Almodovar III, and Luis Omar Ocasio-Capo.

Jose Honorato was desperately awaiting news about his brother Miguel, 30, who was at the club with three friends. The friends were safe, but Jose struggled to determine if Miguel was at one of several hospital treating the wounded or was one of the bodies lying dead in the club.

"My brother's wife called me looking for him after she heard the news," he said. "I called his cell phone and he would not answer."

Adeliz Lopez said she just learned her cousin, Ilka, is in critical condition after being shot eight times. Ilka went to Pulse for Latin Night, but what was supposed to be a fun evening of dancing ended in a nightmare, she said.

"I'm devastated," Lopez said. "There is so much hate in people's heart."

Information on the tragedy slowly was revealed through the early morning hours.

"We can confirm this is a mass casualty situation. Support from local/state/federal agencies," Orlando police tweeted about four hours after the initial gunfight. Then, a short time later: "Pulse Shooting: The shooter inside the club is dead."

A bomb squad was at the scene, and police reported conducting a "controlled explosion." Hours after the shooting, police were still trying to piece together what happened.

"Anyone who was at Pulse nightclub and was a witness please come to the Orlando Police HQ," the department tweeted. "Any information you have could aid investigators in this case."

June is Gay Pride month across the nation, and Orlando recently wrapped up its annual week-long Gay Days festival. Up to 150,000 in the LGBT community attended area theme parks, gay nightclubs and special events. It remains one of the largest gay pride events in the world.

Saturday night into Sunday the club was celebrating Latin Night. Club patron Christopher Hansen told CNN he heard what could have been 20 or 30 shots, setting off a panic as people scrambled for cover or raced for the exits. He said he helped a couple people who were wounded.

"It's just shocking," said Hansen, who crawled to safety. "I just saw bodies going down."

As the tragedy was unfolding, Pulse Orlando posted to its Facebook page: "Everyone get out of Pulse and keep running."

The shooting spree came just one day after The Voice star Christina Grimmie was shot and killed after a concert Friday night at the Plaza Live Theater in Orlando. That gunman, identified as Kevin James Loibl, 27, of St. Petersburg, Fla., fatally shot himself after the attack.

Bacon reported from McLean, Va. Contributing: Steph Solis, Chris Bonanno, John Torres,

Carolyn McAtee Cerbin,and Jennifer Sangalang, USA TODAY Network