You are not permitted to download, save or email this image. Visit image gallery to purchase the image.
The men had driven their car into the police yard before getting out to stage the attack, Setyo Wasisto, national police spokesman, told a briefing.
Two officers were wounded in the attack, while another was killed after one of the perpetrators tried to escape and crashed into the officer, he said.
"The one who escaped has been captured and secured at Pekanbaru police station," Wasisto said.
The spokesman said that a journalist who had been at the police station was also hurt after being hit by the car.
Earlier, an internal police report said that one of the dead men had a suspected bomb strapped to his body. Wasisto did not comment on this.
TV footage showed one man lying on the ground with a long sword next to his body and an armoured car stationed outside the police station.
A police spokesman in Riau said they had not identified the perpetrators yet or determined their motive.
But the attack comes after a series of suicide bombings by Islamist militants targeting churches and a police building in Indonesia's second-biggest of city of Surabaya over the past few days.
The suicide bombings, involving families with young children, and an explosion at an apartment where militants were suspected to have been constructing bombs have left around 30 people dead, including 13 suspected perpetrators, police said.
The attacks are the worst in the world's biggest Muslim-majority country since the bombing of tourist-packed restaurants in Bali in 2005.
Police suspect they were carried out by a cell of the Islamic State-inspired group Jemaah Ansharut Daulah (JAD), an umbrella organisation on a U.S. State Department terrorist list that is reckoned to have drawn hundreds of Indonesian sympathisers of Islamic State.
In a message carried on its Amaq news agency, Islamic State has claimed responsibility for the attacks in Surabaya.
After some major successes tackling Islamist militancy since 2001, Indonesia has seen a resurgence in recent years, including in January 2016 when four suicide bombers and gunmen attacked a shopping area in the capital, Jakarta.