An earthquake of magnitude 5.8 shook northern Pakistan on Tuesday, killing eight people and injuring 100, government and police officials said.