The gunman who opened fire inside a crowded nightclub here early Sunday morning, launching a rampage that killed 50 people and injured 53 others in the deadliest shooting spree in the country's history, had pledged allegiance to the Islamic State before the attack, according to US law enforcement officials.