KARACHI, Pakistan—At least 43 people were killed when gunmen ambushed a bus in this southern port city, Pakistani officials said, in a sectarian assault that was the country’s first major attack claimed by Islamic State.

The victims were Ismailis, members of a branch of Shiite Islam, who were traveling together on a bus Wednesday morning.

While...