Gunmen killed at least 31 people in Pakistan 's southern port city of Karachi as a by-election was held Sunday to replace a lawmaker murdered earlier this year .