A 5.1-magnitude earthquake hit parts of Pakistan's northwest Khyber Pakhtunkhwa province on Tuesday, the met office said.