But in the hours after he spoke, law enforcement officials said that the gunman had pledged his allegiance to the Islamic State, and they acknowledged that he had twice been investigated for terrorism connections.