The epicenter of the tremor, originating at a depth of 28.9 kilometres, was about 100 km from Islamabad in Hazarsa region of Khyber Pakhtunkhwa province, according to the US Geological Survey.
At least two aftershocks followed the quake which created panic among the people, said policeman Akram Khan.
"So far there are reports that five people were injured but none of them seriously," he said, adding that some properties were also damaged.
The tremor was also felt in Islamabad and in parts of Pakistan-occupied Kashmir.