Officials said the incident occurred on Tuesday outside Asadabad, the capital of the eastern province of Kunar, where remnants of the former Taliban regime and allied militants are known to operate.
Mohammad Hassan Farahi, the deputy provincial police chief, said: "Two rockets were fired by the enemies of Afghanistan.
"One hit the compound of a primary school where children including girls were busy studying in the yard."
Government officials refer to Taliban and their Islamist militant allies as "enemies of Afghanistan".
Asdabad is close to a base for US-led coalition forces tracking Taliban and al-Qaeda militants in Afghanistan.
A second rocket also landed near the school, hitting a police base, but Farahi said he had no information about any casualties or damage there.
Farahi blamed Taliban militants for attacking the school as part of a campaign against government-sponsored education.
But a purported Taliban spokesman, Qari Mohammed Yousaf, denied involvement, telling The Associated Press in a telephone interview that: "We do not kill innocent children. This is not our work."
According to Fahari, hundreds of boys aged from six to 16 were in the school at the time
Omar Sahib, 12, said: "I saw so many children on the ground. Many were not moving. Screams were coming from everywhere. I was crying. One teacher was lying there without a leg."
The US military said in a statement: "This despicable act clearly demonstrates the enemy's complete disregard for the Afghan people.
"The Afghan National Army and coalition forces will hunt down these terrorists and ensure they're held responsible."