Authorities were investigating it as an act of terrorism.
At least 53 other people were hospitalized, most in critical condition, officials said. A surgeon at Orlando Regional Medical Center said the death toll was likely to climb.
Mayor Buddy Dyer said all of the dead were killed with the assault rifle.
“There’s blood everywhere,” Dyer said.
The suspect exchanged gunfire with an officer working at the gay club known as Pulse around 2 a.m., when more than 300 people were inside. The gunman then went back inside and took hostages, Police Chief John Mina said.
Around 5 a.m., authorities sent in a SWAT team to rescue the hostages.
Jackie Smith, who was inside the club, said two friends next to her were shot.
“Some guy walked in and started shooting everybody. He had an automatic rifle, so nobody stood a chance,” Smith said. “I just tried to get out of there.”
In addition to the guns, the shooter also had some sort of “suspicious device,” Mina said.
Authorities were looking into whether the attack was an act of domestic or international terror, and if the shooter acted alone, according to Danny Banks, an agent with the Florida Department of Law Enforcement.
“This is an incident, as I see it, that we certainly classify as domestic terror incident,” Orange County Sheriff Jerry Demings said.
The suspect was identified as Omar Mateen of Port St. Lucie, Fla.
Rep. Alan Grayson named the shooter, citing law enforcement officials. A federal law enforcement official with knowledge of the investigation also confirmed the name. The official was not authorized to discuss the investigation publicly and spoke on condition of anonymity.
FBI agent Ron Hopper said there was no further threat to Orlando or the surrounding area.
When asked if the gunman had a connection to radical Islamic terrorism, Hopper said authorities had “suggestions that individual has leanings towards that.”
Authorities said they had secured the suspect’s vehicle, a van, right outside the club.
Relatives and friends, many in tears, gathered outside the hospital to learn whether their loved ones were among the dead or wounded.
Smith did not know the conditions of her friends and came out of the hospital and burst into tears.
The wounded included one police officer who was shot and suffered injuries to his face, officials said.
Police had said previously on Twitter that there was a “controlled explosion” at the scene of the shooting. Mina said that noise was caused by a device intended to distract the shooter.
A woman who was outside the dance club early Sunday was trying to contact her 30-year-old son, Eddie, who texted her when the shooting happened and asked her to call police. He told her he ran into a bathroom with other club patrons to hide. He then texted her: “He’s coming.”
“The next text said: ‘He has us, and he’s in here with us,’ ” Mina Justice said. “That was the last conversation.”
Pulse posted on its own Facebook page around 2 a.m.: “Everyone get out of Pulse and keep running.” Just before 6 a.m., the club posted an update: “As soon as we have any information, we will update everyone. Please keep everyone in your prayers as we work through this tragic event. Thank you for your thoughts and love.”
Local, state and federal agencies were investigating.
President Barack Obama was briefed on the attack and asked for regular updates on the investigation, the White House said.
The attack follows the fatal shooting late Friday of 22-year-old singer Christina Grimmie, who was killed after her concert in Orlando by a 27-year-old Florida man who later killed himself. Grimmie was a YouTube sensation and former contestant on “The Voice.”
Jon Alamo said he was at the back of one of the club’s rooms when a man holding a weapon came into the front of the room.
“I heard 20, 40, 50 shots,” Alamo said. “The music stopped.”
Club-goer Rob Rick said the shooting started just before closing time.
“Everybody was drinking their last sip,” he said.
He estimated more than 100 people were still inside when he heard shots, got on the ground and crawled toward a DJ booth. A bouncer knocked down a partition between the club area and an area in the back where only workers are allowed. People inside were able to then escape through the back of the club.
Christopher Hansen said he was in the VIP lounge when he heard gunshots. He continued to hear shooting even after he emerged and police urged people to back away from the club. He saw the wounded being tended to across the street.
“I was thinking, ‘Are you kidding me?‘ So I just dropped down. I just said, ‘Please, please, please, I want to make it out,‘” he said. “And when I did, I saw people shot. I saw blood. You hope and pray you don’t get shot.”