The epicentre of the tremor was near Hazro in Attock district of Punjab province, Pakistan Meteorological Department said.
"It occurred at a depth of 12 kilometres," the department said in a tweet.
The tremor was felt in Nowshera, Haripur and Swabi district of Khyber Pakhtunkhwa, local media reported, adding that people rushed out of their buildings in panic.
No loss of life or damage to property has been reported.
Pakistan has experienced several quakes in the past, including a 5.3-magnitude tremor last month. The worst was in 2005 which killed more than 74,000 people.