Jakarta (AFP) - Two alleged Islamic State group militants stabbed a police officer to death in western Indonesia, authorities said Sunday, in the latest assault targeting officials in the world's most populous Muslim country.

The two attackers shouted "Allahu Akbar", or God is great, as they entered a security post in North Sumatra's police headquarters in Medan city where they stabbed a police officer, officials said.

Several police officers fought back against the militants, killing one and critically injuring another.

"We suspect the attackers have links with IS and Bahrun Naim, because we found a IS flag, books and CDs linked to IS in the house of one attacker," national police spokesman Setyo Wasisto told AFP.

Bahrun Naim, an Indonesian who is fighting with IS in Syria, has been accused of directing a series of mostly botched terror plots in his homeland in recent years.

Hundreds of radicals from Indonesia have flocked abroad to fight with IS, and the country has seen a surge in plots and attacks linked to the jihadists over the past year.

The attack happened just hours before Eid prayers were held, including at the North Sumatra police headquarters, as part of the Eid al-Fitr celebrations that mark the end of the holy fasting month of Ramadan.

Police are also investigating whether Sunday's incident was linked to the recent capture of three militants accused of plotting to attack police, Wasisto added.

In May suicide bombers killed three police officers at a bus station in Jakarta in the deadliest attack in Indonesia since January 2016, when a suicide blast and gun assault claimed by IS left four assailants and four civilians dead in the capital.

Indonesia has long struggled with Islamic militancy and has suffered a series of fatal attacks in the past 15 years, including the 2002 Bali bombings that killed 202 people.

A sustained crackdown weakened the country's most dangerous networks but the emergence of IS has proved a potent new rallying cry for radicals.