A Pakistan military statement said troops from its Frontier Corps returned fire and five Afghan National army soldiers were killed.
Tensions have been running high between Afghanistan and Pakistan over control of the 2,430-km border.
Taliban and al-Qaeda fighters are reported to have taken refuge in Pakistan in order to stage cross-border attacks inside Afghanistan.
Pakistan's move to fence parts of the disputed frontier has also angered Afghanistan.
General Mohammad Zahir Azimi, Afghanistan's defence ministry spokesman, accused Pakistani forces of encroaching 2-3km inside Paktia province's Jajai district.
"Border police tried to stop them, and the Pakistani army started firing heavy weapons toward the Afghan forces," he said.
Earlier, General Abdul Rahman, the chief of the Afghan border police, said five policemen were wounded.
A local official said heavy weapons fire hit the village of Kubki and a school, bazaar and clinic in Gul Ghundi village, wounding villagers and students.
"The Pakistanis launched artillery, shot their guns, and they left behind civilian casualties in the area," Rahmatullah Rahmat, Paktia's governor, said.
"It is a clear violation - crossing the border to attack Afghanistan."
He said Afghan forces only fired back with assault rifles.
Pakistan has denied trespassing into Afghan territory or hitting civilian targets.