Media playback is unsupported on your device Media caption A witness filmed as police in Jakarta engaged in a fierce gun battle

The so-called Islamic State (IS) has said it was behind a series of explosions and gun attacks in the Indonesian capital Jakarta.

At least two civilians and five attackers died in the assaults, described as an attempt to mimic the deadly Paris attacks.

Security forces battled militants for hours in a major business and shopping district.

It follows warnings late last year that Islamists were planning a major attack.

IS released a statement online claiming the attacks, which it said were carried out by "soldiers of the Caliphate", targeting "citizens of the Crusader coalition" against the group.

Media playback is unsupported on your device Media caption Jakarta attack: Video captures Starbucks blasts

Image copyright Google+ post Image caption Alleged mastermind Bahrun Naim is currently believed to be in Syria with IS

Jakarta Police chief Tito Karnavian said Indonesian national Bahrun Naim, who has been known to the authorities since at least 2010 and is currently thought to be in Syria, had been "planning this for a while".

Profile: Suspected mastermind Bahrun Naim

At the scene: BBC's Ali Moore in Jakarta

If you didn't know and didn't look too closely, you could be standing near the site of today's bombings in Jakarta and have no idea this country has just experienced its worst terror attack since 2009. Hours after it began, the street has been swept, the blood washed away, and the traffic is flowing.

But look closer and there's a hole in the road where suicide bomb went off. The traffic is lighter than usual and the street food hawkers are doing a less than brisk trade, even though dozens of people are milling around, having a look, staring at the flowers of condolence placed in the centre of the intersection.

Many here have been worried about the rise of IS and what that means for home-grown terror groups. Today perhaps they got the beginnings of an answer.

The assault began late morning local time, when blasts struck near a Starbucks cafe and police security post, in an area close to embassies and government buildings.

"There was lot of commotion, a lot of craziness," said Rob Phillips, an English teacher who lives in the area.

"We heard a large bang. We thought it was thunder because the storms here are pretty big."

Gunmen fled to the Djakarta Theater, part of the same complex that houses the Starbucks, where a standoff developed with police.

Explosions and gunfire rang out for hours before police declared the situation under control.

Two of the attackers were killed in a suicide bombing, police said, with the other three killed in gun battles with police.

A Canadian and an Indonesian national, both civilians, also died.

Bodies of the militants who were killed were left sprawling in the street. Police said 20 people were injured in the attacks, including five police officers.

Several foreigners are also reported to be among the wounded, including one Dutch national.

Image copyright Reuters Image caption The attacks sparked chaotic scenes in Indonesia's capital

The attack on the Indonesian capital is sadly part of a pattern that has been repeating itself in several cities around the world in recent months, the BBC's security correspondent Frank Gardner says.

Istanbul, Paris and now Jakarta have all experienced what counter-terrorism officials classify as a "Marauding Terrorist Firearms Attack", or MTFA for short.

Preventing such attacks requires better intelligence and needs more effective sharing of information among the people who need to know it, our correspondent adds.

National police spokesman Anton Charliyan said the perpetrators had "imitated" the Paris attacks.

He said police had received warnings in November from IS they were planning a "concert in Indonesia", meaning an attack.

Indonesian President Joko Widodo has called on his country not to be defeated by "these acts of terror".

Several foreign governments advise caution while visiting Indonesia, with the UK Foreign Office urging its nationals to "maintain vigilance" after the attacks.

Islamist attacks in Indonesia

Indonesia has suffered militant attacks in the past, but has been relatively successful in curbing home-grown Islamist extremism after a spate of attacks in the last decade. Some of the deadliest include:

July 2009: Seven people killed and dozens wounded when two suicide bombers target Marriott and Ritz Carlton hotels in Jakarta

Oct 2005: Suicide attacks in Bali leave 23 dead, including the bombers

Sept 2004: Bomb outside Australian embassy in Jakarta kills at least nine people

Aug 2003: Bomb at Jakarta's Marriott Hotel kills 12

Oct 2002: Bali bombings kill 202, including 88 Australians

Dec 2000: Church bombings across the country kill 19

IS influence in Indonesia

Indonesia was on high alert over the new year period after threats from IS.

Up to 200 Indonesians are estimated to have gone to Syria to fight with IS.

Indonesia is the world's most populous Muslim nation but is largely secular, although in recent years the threat of radicalism has remained high as small networks of militants are still thought to be operating in the country.