Updated

PESHAWAR, Pakistan -- Hundreds of militants crossed from Afghanistan and attacked several border villages in Pakistan on Wednesday, triggering shootouts with local militias that killed at least five people, police said.

It was the latest in a spate of such cross-border attacks, which have raised tensions between Kabul and Islamabad and undermined efforts on both sides to crack down on Al Qaeda and the Taliban. A similar attack on the Afghanistan side of the border Tuesday killed at least 12 border policemen, officials said.

The two nations have accused each other of not doing enough to stop militants from slipping across the porous border, and Afghanistan has also blamed Pakistan for firing hundreds of rockets into its territory in recent months that killed dozens of people.

Paramilitary troops and police were sent to the villages attacked Wednesday in Pakistan's Upper Dir district to help armed tribesmen there who were trying to fend off the insurgents, local police official Gul Fazal Khan said.

The militants torched two schools and a mosque in the village of Nusrat Dara, and destroyed a school in the adjoining village of Saro Kili, said Ghulam Mohammed, a top government official in Upper Dir. They used rockets, mortars and heavy machine guns along with assault rifles.

Security forces killed three militants and captured three others during the fighting, he said. Two members of a militia fighting the militants were killed and two others wounded, he added.

On Tuesday, at least 150 militants came from Pakistan and overran three border checkpoints in eastern Afghanistan near the border with Upper Dir, said Sediq Sediqqi, a spokesman for the Afghan Interior Ministry. At least 12 Afghan border policemen were killed, he said.

Pakistan has complained that militants coming from Afghan bases have killed at least 55 members of the security forces and tribal police over the last month. It has also blamed the U.S. for the recent attacks since many American forces pulled out of Kunar over the last year to focus on more populated areas.

Both Kabul and Washington have long accused Pakistan of not doing enough to stop militants from crossing into Afghanistan to stage attacks. Afghanistan has also complained that Pakistan has fired more than 750 rockets into eastern Afghanistan since May that have killed at least 40 people.

The Pakistan army denies it has intentionally fired rockets into Afghanistan, but acknowledges that several rounds fired at militants conducting cross-border attacks may have landed over the border.

Pakistani Prime Minister Yousuf Raza Gilani called Afghan President Hamid Karzai on Wednesday to express concern about the recent cross-border attacks. He told Karzai that the Pakistan army was "exercising utmost restraint" despite the attacks, but the situation "needs to be defused quickly," according to a statement released by the prime minister's office.

Also Wednesday, Pakistani soldiers clashed with militants in a rare gun battle in a key sanctuary for Taliban and Al Qaeda fighters along the Afghan border that the U.S. desperately wants Pakistan to clear, intelligence officials said.

The fierce firefight in Miran Shah, the main town in the North Waziristan tribal area, lasted roughly six hours, killed five people and sent shoppers in the bazaar scurrying for safety, said the officials, speaking on condition of anonymity because they were not authorized to talk to the media.

The clash underscored the danger of Pakistan's refusal to launch an offensive in North Waziristan. It also signaled how the military could potentially get drawn into a conflict in the remote area against its will.

The Pakistan army has more than 30,000 troops in North Waziristan, but battles with militants in the area have been rare.

The army says its troops are stretched too thin by operations in other parts of the border area to launch an offensive. But many analysts believe the government is reluctant to target Afghan militants with whom it has historical ties and could be useful allies in Afghanistan after foreign forces withdraw.

However, North Waziristan is also filled with many Pakistani Taliban fighters and their allies who have declared war against the state and have carried out many attacks against Pakistani security forces and civilians throughout the country.

It is unclear which militants were involved in Wednesday's battle.

The conflict started Tuesday with a roadside bomb attack on an army convoy on the outskirts of Miran Shah that killed three soldiers and wounded 14 others, said intelligence officials. The army suspected the attack was directed from a nearby hospital that is reportedly used to treat militants, so soldiers destroyed part of it, said the officials.

When soldiers went to destroy the rest of the hospital Wednesday morning, they took heavy fire from militants in the Miran Shah bazaar and eventually had to call in helicopter gunships for support, said the officials.

Four militants and one civilian were killed in the crossfire, and 10 other people were wounded, including five army troops, four militants and one civilian. The officials spoke on condition of anonymity because they were not authorized to talk to the media.