Intelligence services in Kenya were warned that al-Shabaab was planning terrorist attacks on high-profile targets in the east African country around Christmas and the new year, western and regional security officials have said.
Officials and other sources told the Guardian the warnings had been passed on several times in recent months, adding that they had been frustrated not to see a greater response from Kenyan authorities.
Security forces cleared the hotel, restaurant and office complex in Nairobi on Wednesday morning after it was attacked the previous day by four gunmen from al-Shabaab, an Islamic extremist organisation based in neighbouring Somalia. The Kenyan president, Uhuru Kenyatta, said 14 civilians were confirmed dead.
Al-Shabaab, which has said its mujahideen were responsible for the assault, has launched a series of terrorist operations in Kenya in recent years. In 2013, the al-Qaida affiliate took over a luxury mall in Nairobi, killing 67 people.
The news of the warnings will embarrass authorities in Kenya, which is seen as a key local counter-terrorist player by the US, UK and other western powers.
One Kenyan intelligence official said information passed on by security partners about planned attacks lacked detail but that the country had been on high alert since November.
Another security source told Associated Press the extremists had confused security officials by changing target locations.
The officials spoke on condition of anonymity because they were not authorised to speak to reporters.
Al-Shabaab has waged a decade-long insurgency to impose its rigorous version of Islamic law on Somalia and, though it has been forced out of major cities, controls much of the anarchic failed stateâ€™s southern and central rural areas. In October 2017, an al-Shabaab truck bomb killed more than 500 people in the capital, Mogadishu. The group often attacks restaurants and hotels, using tactics similar to those employed in Nairobi.
Experts said Wednesdayâ€™s attack was designed to attract media attention.
â€œA terror attack is â€¦ purely media theatre. The number of casualties is not the primary objective. It is to attack a high-profile target, especially where westerners are going to be so the west is interested,â€� said Hussein Sheikh-Ali, a former national security adviser in Somalia and chairman of the Hiraal Institute, a Mogadishu-based research centre.
In the last year, al-Shabaab has been the target of an intense campaign of US airstrikes. These have inflicted significant casualties and killed several senior leaders.
â€œThis [recent] Nairobi attack is a response first and foremost to the airstrikes. They are sending a message that the US strikes have not degraded them as the US military and some media have claimed. They are saying â€˜we are in businessâ€™,â€� Ali said.
A second factor may be to influence public opinion in Kenya. Kenyan forces are deployed in Somalia as part of multinational efforts to fight al-Shabaab. The Nairobi attack took place on the third anniversary of a huge assault on a Kenyan base in Somalia by militants in which as many as 180 Kenyan soldiers may have died.
Rashid Abdi, a Nairobi-based expert on al-Shabaab with the NGO International Crisis Group, said the terror groupâ€™s propaganda consistently highlighted the Kenyan presence in Somalia, but pointed out that international links meant there was a wider agenda driving the extremists too.
â€œIf the Kenyans withdrew it would remove a big reason why al-Shabaab like to strike Kenya but if you have a group like al-Shabaab which is part of a global jihad movement then they would still find another reason. They see Nairobi with its big western presence as a bastion of the west,â€� Abdi said.
Kenyan police have foiled several similar al-Shabaab attacks over recent years, though several investigations have shown corruption has allowed extremists to move with ease across the border with Somalia.
The group has some networks in Kenya itself, mainly providing logistic support and recruits. However, attackers are often brought in from Somalia.
Al-Shabaab has its own internal problems, suffering from a lack of funds and manpower that have forced it to impose unpopular taxes on local communities. The movement is riven by factional feuding and faces competition from Islamic State.
Earlier this week, al-Shabaab media reported the group had executed an Isis commander in Somalia.