President Obama on Saturday committed the United States to an intensified fight against terrorists in East Africa, announcing here that his administration would expand support for counterterrorism operations in Kenya and Somalia, including increased training and funding for Kenya’s security forces.

“We have to keep that pressure going even as we’re strengthening the Somali government,” he said at a joint news conference with Kenyan President Uhuru Kenyatta.

Obama acknowledged that al-Shabab terrorists retain the capacity to attack “soft targets” in both countries, even after years of American drone strikes and efforts from a regional, U.S.-backed counterterrorism force based in Somalia. But he said al-Shabab’s territory had been “systematically reduced.”

Obama came to office vowing to move the United States off a perpetual war footing and promising to wage a smarter, swifter war on international terrorism.

But his East African sojourn this week serves as a stark reminder that seven years into his presidency the long, difficult fight against terrorism remains a central and vexing component of his foreign policy.

“As is true around the world, what we find is, is that we can degrade significantly the capacities of these terrorist organizations, but they can still do damage,” Obama said at the news conference. “And part of our announcement today involves additional funding, additional assistance that we’re providing the Kenyan security forces to deal with these very specific counterterrorism threats.”

Obama’s discussions with Kenyatta have been dominated by the question of how best to counter Islamist extremists engaged in regular attacks against civilians. “We are deepening that democracy while fighting global terrorists who seek to destroy our way of life,” Kenyatta said. “Left undefeated, they will redraw the international system and make room for violent extremism and tyranny.”

Kenyatta said his country is new to the fight against terror and is learning from partners such as the United States, and added: “This is an existential fight for us.”

Security will also be similarly dominant during the president’s time in Ethiopia, a nation that has worked to keep the instability in Somalia from spilling across its borders and that has dispatched peacekeeping forces to South Sudan and elsewhere.

“Counterterrorism will certainly be a focus” national security adviser Susan E. Rice told reporters before Obama left for the trip. While al-Qaeda affiliates are the primary concern in East Africa, Rice said, “in West and North Africa, obviously we have seen [the Islamic State] become an increasing presence, particularly in the Maghreb, but also in Nigeria.”

Kenneth Menkhaus, a political science professor at Davidson College, said it is hard to be hopeful that closer cooperation between countries could resolve the region’s problems anytime in the near future.

“The Horn of Africa presents extraordinarily complex political and security dilemmas, for which there’s no obvious answer,” Menkhaus said in an interview. “The question really is which is the least bad choice, and how can you kick open doors which, down the road, could present opportunities for conflict resolution.”

Obama’s decision to visit the African Union’s headquarters in Addis Ababa, Ethiopia — the first sitting U.S. president to do so — is part of his push to build capacity among African nations to address the problems of their region.

Ethiopia and Kenya — both of which border Somalia and South Sudan, countries that remain riven by deep conflict — have contributed troops to multiple regional peacekeeping operations. Both are part of the African Union Mission in Somalia (AMISOM), and the U.N.-African Union Mission in Darfur (UNAMID). Ethiopia is also part of another U.N. force in Sudan and played a key role in trying to broker a peace agreement in South Sudan, while Kenya has sent troops to the U.N. peacekeeping mission there.

In 2015, Kenya received $100 million in U.S. counterterrorism assistance — more than doubling the amount allocated the previous year.

As a result of this weekend’s talks, the Massachusetts National Guard and the Kenyan government will sign a partnership agreement, a senior administration official said, and the administration has pledged to work with Congress to provide additional counterterrorism aid to Kenya.

Vicki Huddleston, who served as U.S. ambassador to Mali as well as deputy assistant secretary for Africa at the Pentagon, said the two countries “have stepped forward in the fight against terrorism in Somalia, and we need to recognize Ethiopia for what it’s done regarding terrorism and extremism in the region.”

Obama has promoted U.S. counterterrorism work with allies in Somalia and Yemen as a model for how the United States can pursue its security goals without deploying combat troops.

Ethiopia has widely been perceived as having an effective military force, including in its Ogaden region, which is largely Somali, though some of its efforts have been accompanied by acts of political repression.

Al-Shabab launched two horrific attacks in the past two years: the September 2013 occupation of Nairobi’s Westgate shopping mall, which left 67 dead, and the strike in April at Garissa University College in Kenya, which took the lives of 147. Those losses have seared the consciousness of Kenyan leaders in the same way the Sept. 11, 2001, attacks affected American politicians.

Obama noted those attacks in his remarks Saturday. “Earlier, I had the opportunity to meet with survivors and families of victims of the bombing of our U.S. Embassy in 1998,” Obama said at the news conference. “In the face of despicable violence, such as the attack on Garissa University College and the Westgate Mall, the Kenyan people have shown incredible resolve and remarkable resilience.”

Part of the aim of Obama’s visit is to bolster that resolve. “On security, the United States and Kenya are already strong partners,” he said, “and today we reaffirm that we stand united in the face of terrorism.”

Mwenda Njoka, a Kenyan Interior Ministry spokesman, said in an interview that “terrorism is the key threat we face” and that Kenya needs more U.S. aid to wage the battle.

“We need technology that allows us to monitor and prevent the enemy’s efforts at recruitment,” Njoka said. “Whether that’s surveillance or encryption technology, we know the Americans have the capacity to do this.”

The country’s security forces were heavily criticized after the Westgate attack, which they failed to prevent despite warnings from Kenyan intelligence agents. Officials admit those mistakes and say they have improved their capacity.

“The left hand didn’t know what the right was doing,” Njoka said, calling Westgate “a wake-up call.”

But Kenya’s renewed determination to fight extremists has come at a cost.

Some of the country’s efforts to crack down on terrorists within its borders have prompted an outcry from Muslim organizations and human rights groups, who say that a combination of ethnic profiling and corruption have undermined the efforts’ effectiveness and fueled extremism.

One of the most notorious counterterrorism operations occurred in 2014, when Kenyan police rounded up more than one thousand Somali refugees and Kenyan Muslims in Nairobi and detained them in a large soccer stadium for days. Kenyan officials said it was a crucial operation to prevent another attack, but human rights groups said it was unlawful and inhumane.

Obama will be speaking in the stadium during his visit — a shock to Kenya’s Somali community, which remains troubled by the operation.

At Saturday’s news conference, he encouraged the Kenyan government not to persecute or alienate minority groups in its efforts to crack down on terrorism. Al-Shabab has long tried to recruit fighters in Kenya by pointing to the security forces’ mistreatment of Muslims.

“We need to make sure the approaches taken in rooting out potential terrorist threats don’t create more problems than they solve,” Obama said.

Muslims make up roughly 11 percent of Kenya’s population; Somali refugees in the country number nearly 422,000, and the number of Kenyans of Somali origin is estimated to be more than 2 million.

Al-Amin Kimathi, who chairs the Muslim Human Rights Forum, said the tactics have “led to a polarization of Kenyan society” and have been “one major contributor to the radicalization that we’ve seen across the republic.”

Sen. Christopher A. Coons (D-Del.), a member of the Senate Foreign Relations subcommittee on African affairs, who joined the president on his trip to Africa, said Kenya, like other countries, needs to think through how to balance respect for human rights with its efforts to maintain the security of its people.

“How democracies respond to terrorism is an enduring challenge for all of us,” Coons said.