The gunmen lobbed grenades and fired automatic weapons outside the Central Reserve Police Force (CRPF) camp in Indian-administered Kashmir before dawn, a spokesman said.
"They tried to storm the camp but they were not even allowed to enter the gate," CRPF spokesman Bhuvesh Choudhary told AFP.
Choudhary described the men as "heavily armed fidayeen", a term commonly used to mean suicide attacker in Kashmir.
"All the four attackers were eliminated in a clean and wonderful operation. There were no injuries on our side," he added.
Four assault rifles, grenades and other ammunition were recovered from the bodies of the slain attackers, whose identities were not known.
No group has claimed the attack.
"They were carrying huge amounts of ammunition and did not appear to be locals," said director general of police, S. P. Vaid.
The foiled attack in the northern Sumbal area came amid renewed tension in Kashmir following the killing last month of a top rebel leader, which sparked fresh protests against Indian rule.
Kashmir has been divided between India and Pakistan since the end of British rule in 1947, but both claim the territory in its entirety.
Rebel groups have since 1989 been fighting roughly 500,000 Indian soldiers deployed in the region, demanding independence or a merger with Pakistan.
The fighting has left tens of thousands dead, most of them civilians.
Dozens of local youths have joined the rebel ranks since last year when the killing of a popular rebel commander sparked widescale anti-India protests that left more than 100 civilians dead and thousands wounded.
India regularly accuses Pakistan of arming and training rebels and sending them across the heavily militarised Line of Control (LoC) that divides the territory to attack its forces.
Islamabad denies the allegations.