A policeman was hacked to death with a machete in an Islamist attack just days before 20 people were slaughtered in the Bangladeshi capital.

The terrorists carried out the latest deadly assault near a huge prayer in Kishoreganj where 200,000 people had gathered to celebrate the end of Ramadan.

A bomb was thrown in front of police at Azim Uddin High School, which was being used by officers a checkpoint, before Molotov cocktails were thrown and gunfire was exchanged between terrorists and police, killing four and injuring at least 12 on Thursday morning.

Scroll down for video

A suspected attacker is being detained by police officers after a bomb attack near the Sholakia Eid in Solakia, Kishoregonj, Bangladesh

The body of a suspected attacker lies on the ground after a bomb attack near the Sholakia Eid in Solakia, Kishoregonj, Bangladesh

Police operations during the bomb attack near the Sholakia Eid in Solakia, Kishoregonj, Bangladesh

Local TV station Somoy TV broadcast footage of the gunfight and reported the slain policeman had been hacked to death, who was one of two officers killed.

The other two was a woman named Jharna Rani Bhoumik and one of the attackers, according to the Dhaka Tribune.

The officers killed have been identified as Zahirul Islam and Ansarul who died in the initial bomb blast and two suspects were arrested.

Six injured policemen were transferred to Mymensingh Medical College Hospital after the bomb was hurled at them at 9.30am.

A revolver, machete and hand bomb were all recovered from the scene and one of the suspects arrested had been injured by gunfire.

Azim Uddin High School is less than 500m from the Sholakia Eid congregation and the road nearby the school leads where 200,000 Muslims were praying.

A policeman was hacked to death with a machete in an Islamist attack just days before 20 people were slaughtered in the Bangladeshi capital

A bomb was detonated at a school police were using as a checkpoint before Molotov cocktails were thrown and gunfire was exchanged between terrorists and police, killing four and injuring 12 on Thursday

The terrorists carried out the latest deadly assault near a huge prayer in Kishoreganj where 200,000 people had gathered to celebrate the end of Ramadan

It's understood the terrorists were hiding inside the school, less than a mile away from the 200,000 Muslims celebrating Eid.

He was descending at the prayer by helicopter when the terrorists struck.

Mahbubur Rahman, a police officer in the district control room, said: 'They threw a bomb at a police checkpost. A police constable was killed in the explosion. One attacker was killed and another was arrested.'

Tofazzal Hosain, who is the district's deputy police chief, said several people had taken part in the attack and some had been armed with machetes - a hallmark of recent Islamist killings in Bangladesh.

'They first threw a small bomb targeting police and then attacked them with machetes. Police retaliated by returning gunfire,' he said.

The terrorists carried out the latest deadly assault near a huge prayer in Kishoreganj where 200,000 people had gathered to celebrate the end of Ramadan, just as these locals waited to board trains back to their villages

Travelers sit atop an overcrowded train as they travel to their villages ahead of the Eid Al-Fitr celebrations at the Airport Railway Station in Dhaka, Bangladesh, a day before the latest attrocities

Azimuddin Biswas, the district administrator, said the attack had taken place on the premises of a nearby school and not on the actual prayer ground.

'The congregation was not affected by the clashes,' according to Biswas.

Although there was no immediate claim of responsibility for the attack, it comes less than a week after Islamists killed 20 hostages and two policemen in an overnight siege at a Western-style cafe in Dhaka.

Bangladesh has been on a heightened state of alert in the wake of the killings in Dhaka last Friday night and many services that were held on Thursday to mark the start of Eid included pleas from religious leaders for an end to the violence.

Five men, allegedly the gunmen who carried out an attack in the capital Dhaka on July 1, 2016 during which 20 hostages were slaughtered at a restaurant, posing with a rifle in front of a flag of the Islamic State jihadist group at an undisclosed location

Bangladesh security personnel stand on top of armored vehicles after militants took hostages at a restaurant popular with foreigners in Dhaka, Bangladesh, on Saturday

'Allah, protect our country ... and protect our children from the evils of terrorism,' Mohammad Sadequl Islam, the local imam, told a gathering of around 5,000 devotees at Dhaka's Mahakhali neighbourhood on Thursday.

Many of those who attended services in Dhaka could be seen openly weeping as clerics led prayers for a more peaceful and prosperous Bangladesh.

Bangladesh has been reeling from a growing wave of attacks since the turn of the year, many of which have been claimed by the self-styled Islamic State group or an offshoot of the Al-Qaeda network.

However Prime Minister Sheikh Hasina's secular government has consistently denied that international jihadist networks have gained a foothold in the mainly Muslim country and have said the weekend attack in Dhaka was carried out by members of a local outlawed Islamist group.