FOR months, Indonesia's security forces had been a step ahead of would-be jihadists.
On Thursday, their luck ran out.
Multiple attacks in the political and commercial heart of the Indonesian capital by gunmen armed with explosives and assault rifles left seven people - including five of the assailants - dead.
Two of the militants were taken alive, police said.
The two civilians who were killed were an Indonesian and a Canadian; 20 others, including a Dutchman who works for the United Nations Environment Programme, were wounded.
Indonesia has blamed Islamic State (IS) for the attack, which has brought the radical group's violence to the world's most populous Muslim country for the first time.
"ISIS is behind this attack, definitely," Jakarta's police chief, using a common acronym for IS, told reporters; he went on to name Indonesian militant Bahrun Naim as the man responsible for plotting it.
President Joko Widodo, whose official residence is just 1 km away from the scene, condemned the assault and appealed for calm in a televised statement. He said: "Our nation should not be defeated by these acts of terror."
In the wake of the deadly attacks in Paris, Jakarta has been on high alert. Last month, police here foiled what they said were plans to attack religious minorities during Christmas and New Year holidays. The arrests rounded up members of the Al Qaeda-affiliated Jemaah Islamiyah, which was behind a string of attacks on nightclubs and hotels a decade ago.
In a statement condemning the attacks, Singapore's Ministry of Foreign Affairs said it was attempting to ascertain the safety of its citizens in Jakarta. "We support the Indonesian government in its efforts to bring those responsible to justice."
About half a dozen blasts gutted a police traffic box and shattered the windows of a Starbucks coffee shop. The epicentre was the Sarinah shopping centre, a revered - if somewhat tired-looking - icon and this country's first modern shopping centre dating back to the 1980s.
The scene there was grim. The partially clad bodies of three of the dead lay in the street outside the mall for as long as two hours. The police had initially been reluctant to approach the bodies, worried that they themselves would become the targets of snipers who could have taken positions in the mall's adjoining office building.
Soon though, security forces put on a massive show of force. About two dozen black-clad, heavily armed commandos arrived to secure the scene. At least one explosion was heard as they filed into the mall, now deserted and shuttered.
Along Jakarta's Jalan Thamrin, the main artery for Cabinet ministers and office workers alike, scores of armoured personnel carriers and other vehicles belched out soldiers, who had orders from President Widodo to offer help to the police. The head of Indonesia's intelligence agency, Sutiyoso, and the top general of Indonesia's armed forces, Gatot Nurmantyo, were at the scene.
Even as hundreds of shocked and curious onlookers pushed past police lines, forensics experts raced against rain-laden clouds to comb the scene, ringing shrapnel, glass and bullets with chalk in a debris field stretching 200 m or more.
In the run-up to Thursday's attacks, police and the military made a point of demonstrating their readiness for such incidents, and have even been putting on a united front and invited reporters to witness their "live" anti-terror drills.
Though hard to quantify, social-media support for jihadist groups such as the Islamic State (IS) has enjoyed an uptick. Returning fighters from the front in Syria or Iraq are a potential source of extremists, just as returning mujahidin fighters from Afghanistan were in the 1990s.
Sidney Jones, a Jakarta-based security analyst with the Institute for Policy Analysis of Conflict, said that though Thursday's attacks did not constitute the worst-case scenario involving mass casualties, the government ought to nevertheless introduce laws banning speech inciting terror or support for jihadist groups such as Islamic State.
"The government needs a detailed counter-IS strategy," she said.