NAIROBI, Kenya — Viewing the deadly siege at a shopping mall in Kenya as a direct threat to its security, the United States is deploying dozens of F.B.I. agents to investigate the wreckage, hoping to glean every piece of information possible to help prevent such a devastating attack from happening again, possibly even on American soil.

For years, the F.B.I. has been closely watching the Shabab, the Somali Islamist group that has claimed responsibility for the Nairobi massacre and recruited numerous Americans to fight and die — sometimes as suicide bombers — for its cause.

The Shabab has already attacked most of the major actors trying to end the chaos in Somalia — the United Nations, Uganda, aid groups, the Somali government and now Kenya. The United States has spent hundreds of millions of dollars bankrolling anti-Shabab operations for years, and there is growing fear that the group could turn its sights on American interests more directly, one of the reasons the Obama administration is committing so many resources to the investigation in Kenya.

“We are in this fight together,” said Robert F. Godec, the American ambassador to Kenya. “The more we know about the planning that went into this, the way it was conducted, what was used, the people involved, the better we can protect America, too.”