Suspected militants entered an Indian air force base near the border with Pakistan on Saturday and exchanged fire with security forces for hours, leaving at least four gunmen and two Indian soldiers dead, officials and news reports said.

The attack, which was seen as an attempt to undo recent progress made in the relationship between rivals India and Pakistan, began a couple of hours before dawn, and by late morning it appeared that the violence had ended with the killing of the gunmen by Indian forces. But just two hours later, fresh gunfire erupted.

A helicopter could be seen at around noon firing at an area inside the Pathankot air force base, located about 267 miles north of New Delhi. Shots could also be heard from inside the base.

The defense ministry said just after 5 p.m. that operations at the base were ongoing, 14 hours after the attack began. It added that there had been intelligence reports about a likely terror attack on military installations in Pathankot, and that the air force had been prepared to thwart any attackers.

"Due to the effective preparation and coordinated efforts by all the security agencies a group of terrorists were detected by the aerial surveillance platforms as soon as they entered the Air Force Station at Pathankot," the ministry said in a statement.

It was unclear how many gunmen were still fighting security troops at the base Saturday evening.

The attack began when at least four gunmen entered the living quarters of the base shortly after 3 a.m., but they were unable to penetrate the area where fighter helicopters and other military equipment are kept, said air force spokeswoman Rochelle D'Silva.

Press Trust of India news agency cited police as saying that four attackers were killed following an hourslong gunbattle, and that police started an operation to clear a wider area of other possible intruders.

The attack was viewed by many in India as an attempt to unravel recent progress in the country's relationship with archrival Pakistan. The violence came just a week after Indian Prime Minister Narendra Modi made an unannounced visit to Pakistan to meet with his Pakistani counterpart, Nawaz Sharif.

Modi's visit was seen as a potential sign of thawing relations between the two nuclear-armed neighbors. The two leaders also held an unscheduled meeting at the Paris climate change talks last month.

"These kinds of attacks are nothing new and have generally been the outcome of the dispute of India and Pakistan over Kashmir," said Noor Ahmed Baba, a political scientist at Central University in Indian Kashmir's capital, Srinagar.

The Himalayan region of Kashmir is divided between India and Pakistan, but is claimed in its entirety by both.

Baba said that there were elements in both countries that would like to see the peace process fizzle out, and that all sides must "exhibit political maturity and sagacity to defeat the vested interests."

Ahead of Modi's surprise visit to Pakistan, the national security advisers of both countries had met in Thailand to discuss issues including peace and security, terrorism, the disputed region of Kashmir and ways to maintain peace along the countries' shared border.

The foreign secretaries of both nations are scheduled to meet in Islamabad later this month.

Pathankot, in Punjab state, is on the highway that connects India's insurgency-wracked Jammu and Kashmir state with the rest of the country. It's also very close to India's border with Pakistan.

Police said they suspected the gunmen who entered the air force base were militants, and were investigating whether they had come from the Indian portion of Kashmir or from Pakistan. Rebels routinely stage attacks in Indian-held Kashmir, where they've been fighting since 1989 for an independent Kashmir or its merger with Pakistan.

India accuses Pakistan of arming and training Kashmir's insurgents, a charge Islamabad denies. More than 68,000 people have been killed in the violence in the Indian portion of Kashmir.

Pakistan's foreign ministry condemned the attack. "Building on the goodwill created during the recent high level contacts between the two countries, Pakistan remains committed to partner with India as well as other countries in the region to completely eradicate the menace of terrorism afflicting our region," it said in a statement.

Indian Home Minister Rajnath Singh told reporters that India wants peace with Pakistan, but "if there is any kind of terror attack on India, we will give it a fitting reply."

India's defense minister, national security adviser and the chiefs of the army, navy and air force met Saturday to discuss the situation.

In July, gunmen staged a similar attack at a police station and a moving bus near Gurdaspur, a border town in India's Punjab state. The three attackers then killed four policemen and three civilians before being shot dead by security forces.