The three-hour siege came after police warnings in recent weeks that Islamic militants were planning something big.
There were unconfirmed media reports of more explosions in other parts of the Indonesian capital.
It was the first major violence in the city since the 2009 bombings of two hotels that killed seven people and injured more than 50. Before that, a bombing in a nightclub on the resort island of Bali in 2002 killed 202 people, mostly foreigners.
No one has claimed responsibility for the latest attacks, which took place in front of the Sarinah shopping mall on Thamrin Street and prompted a security lockdown in central Jakarta with enhanced checks all over the crowded city of 10 million.
"This act is clearly aimed at disturbing public order and spreading terror among people," President Joko Widodo said in a statement on television. He was on a working visit to the West Java town of Cirebon, but was returning to Jakarta immediately.
"The state, the nation and the people should not be afraid of, and lose to, such terror acts," he said.
Jakarta police spokesman Colonel Muhammad Iqbal said : "We believe there are no more attackers around Sarinah. We have taken control."
He said two of the attackers were killed by police but did not say how the others died.
Tri Seranto, a bank security guard, said he saw at least five attackers, including three who triggered explosions at the Starbucks. It was not immediately clear if they exploded bombs or grenades.
Mr Tri described them as suicide bombers but General Anton Charilyan, a spokesman for the national police, denied they blew themselves up.
TVOne, a local television network, reported three more explosions in other parts of the city.
After the first explosions a gun battle broke out between the attackers and anti-terror police, and gunfire could be heard more than 90 minutes later.
About two hours later, another explosion was heard from a cafe near the Starbucks, about five minutes after 25 anti-terror police entered. It was not clear if the explosion was a controlled detonation or a bomb.
The area has many luxury hotels, and offices and embassies, including the French. The other set of explosions were in neighbourhoods where the embassies of Turkey and Pakistan are located.
COMMENT RULES: Comments that are judged to be defamatory, abusive or in bad taste are not acceptable and contributors who consistently fall below certain criteria will be permanently blacklisted. The moderator will not enter into debate with individual contributors and the moderator’s decision is final. It is Belfast Telegraph policy to close comments on court cases, tribunals and active legal investigations. We may also close comments on articles which are being targeted for abuse. Problems with commenting? firstname.lastname@example.org