The quake had a magnitude of 7.7, the US Geological survey reported, and was centred in the mountainous Hindu Kush region, 45km (28 miles) south-west of Jarm.
Buildings were evacuated in the capitals of all three countries and communications disrupted in many areas.
Initial reports say at least 13 people have been killed in Pakistan.
There are also reports of a stampede triggered by the quake at a girls' school in the Afghan province of Takhar, which left 12 students dead.
Another five people died in the eastern Afghan city of Jalalabad, hospital sources said.
Officials said the quake happened at a depth of 212km. The magnitude was initially put at 7.7 but later downgraded.
People in the Indian capital Delhi ran into the streets after the tremor struck, and schools and offices were evacuated. The Delhi metro was also briefly halted.
Indian Prime Minister Narendra Modi tweeted that he had ordered an urgent assessment of any damage.
"We stand ready for assistance where required, including Afghanistan and Pakistan," he said.
David Rothery, a professor of planetary geosciences at the UK's Open University, said the quake had the potential to be very damaging.
"Fortunately it occurred at a depth of more than 200km and so the shaking of the ground surface was less than it would have been for a shallower earthquake of the same magnitude," he said.
The region has a history of powerful earthquakes caused by the northward collision of India with central Asia.
In 2005, a magnitude 7.6 quake in Pakistan-administered Kashmir left more than 75,000 people dead.
In April this year, Nepal suffered its worst earthquake on record with 9,000 people killed and about 900,000 homes damaged or destroyed.