The men, dressed in army uniforms, were holed up in the police station, officials said. Gunshots could be heard on television as security forces surrounded the police station in the town of Dinanagar, about 20 km from the border.
The dead included four civilians and two policemen, said H.S. Dhillon, a senior Punjab police officer. Some others were injured, he said.
Home Minister Rajnath Singh said he had spoken to the head of Border Security Force and “instructed him to step up the vigil on India-Pakistan border”.
“I am confident that the situation will soon be brought under control,” he said in a Twitter message.
Gurdaspur is also on the border of the troubled Jammu and Kashmir state, while Punjab has its own history of militancy. India accuses old enemy Pakistan of training and arming militants in both Punjab and Jammu and Kashmir, which Islamabad denies.
India fought a deadly Sikh insurgency in Punjab in the 1980s that peaked with the assassination of Prime Minister Indira Gandhi at the hands of her Sikh bodyguards in 1984.
The attack was in retaliation to her decision to order the army to flush out militants from the Golden Temple in Amritsar, the holiest shrine of the Sikh community.
Sikh militant groups were demanding an independent homeland for minority Sikhs at the time, which they called Khalistan.
“This is probably linked to the movement of the 1990s, these are the Khalistanis who have done this. The remnants of that movement are still being hosted and protected in Pakistan. That is who I assume would be behind it eventually. Directions would have come from there,” said Ajai Sahni, executive director of the Institute for Conflict Management in New Delhi.
The group of about five attackers came in a white Maruti-Suzuki car, dressed in army uniforms, Harcharan Bains, an adviser to Punjab’s chief minister, told Reuters.
Five bombs were also found on a railway track in the state, suggesting a coordinated series of attacks around the time India is marking the anniversary of a near-war with Pakistan in northern Kashmir in 1999.