It took security forces about three hours to end the siege near a Starbucks cafe and Sarinah's, Jakarta's oldest department store, after a team of around seven militants traded gunfire with police and blew themselves up.
A police officer and a Canadian man were killed in the attack, which - with the attackers - took the death toll to seven. Seventeen people, including a Dutch man, were wounded.
Two of the militants were taken alive, police said.
"Islamic State fighters carried out an armed attack this morning targeting foreign nationals and the security forces charged with protecting them in the Indonesian capital," Aamaaq news agency, which is allied to the group, said on its Telegram channel.
Jakarta's police chief told reporters: "ISIS is behind this attack definitely," using a common acronym for Islamic State, and he named an Indonesian militant called Bahrun Naim as the man responsible for plotting it.
The drama played out on the streets and on television screens, with at least six explosions and a gunfight in a movie theatre.
ARMOURED CARS, HELICOPTERS
"The Starbucks cafe windows are blown out. I see three dead people on the road. There has been a lull in the shooting but someone is on the roof of the building and police are aiming their guns at him," Reuters photographer Darren Whiteside said as the attack unfolded.
![Starbucks will close its branches in Jakarta](http://img.astroawani.com/2016-01/51452772630_freesize.jpg)
Police responded in force within minutes. Black armoured cars screeched to a halt in front of the Starbucks and sniper teams were deployed around the neighbourhood as helicopters buzzed overhead.
READ: Starbucks closing Jakarta stores 'until further notice': statement
After the militants had been overcome, a body still lay on the street, a shoe nearby among the debris. The city centre's notoriously jammed roads were largely deserted.
Indonesia has seen attacks by Islamist militants before, but a coordinated assault by a team of suicide bombers and gunmen is unprecedented and has echoes of the sieges seen in Mumbai seven years ago and in Paris last November.
The last major militant attacks in Jakarta were in July 2009, with bombs at the JW Marriott and Ritz Carlton hotels.
The country had been on edge for weeks over the threat posed by Islamist militants. Counter-terrorism police had rounded up about 20 people with suspected links to Islamic State, whose battle lines in Syria and Iraq have included nationals from several Asian countries.
HISTORY OF ATTACKS
Indonesia has the world's largest Muslim population, the vast majority of whom practise a moderate form of the religion.
The country saw a spate of militant attacks in the 2000s, the deadliest of which was a nightclub bombing on the holiday island of Bali that killed 202 people, most of them tourists.
READ: Jakarta blasts: Timeline of militant attacks in Indonesia
Police have been largely successful in destroying domestic militant cells since then, but officials have more recently been worrying about a resurgence inspired by groups such as Islamic State and Indonesians who return after fighting with the group.
Alarm around the world over the danger stemming from Islamic State rocketed after the Paris attacks and the killing of 14 people in California in December.
On Tuesday, a Syrian suicide bomber killed 10 German tourists in Istanbul. Authorities there suspect the bomber had links to Islamic State.
Among those arrested in Indonesia's crackdown late last year was a member of China's Uighur Muslim minority with a suicide-bomb vest. Media said two other Uighur suspects were on the run.
Indonesian security forces have also intensified a manhunt for a militant leader called Santoso, regarded as Indonesia's most high-profile backer of Islamic State, in the jungles of Sulawesi island. Santoso had threatened to unleash attacks in Jakarta.