American military officials said on Monday that they had intelligence that showed the Haqqani network, a ruthless wing of the Taliban based in Pakistan that has become an integral part of the insurgency’s leadership, was behind the attack. One senior United States military official, speaking on the condition of anonymity to discuss intelligence, said the attack had been planned over four to six months and was too sophisticated and “calculated” to have been conducted by other branches of the Taliban.

The resignations of President Ashraf Ghani’s defense secretary and army chief came as no surprise, American officials said, because they came on the heels of another devastating attack in March. In that assault, militants entered the Afghan Army’s main hospital in Kabul and killed more than 50 people in a siege that lasted nearly seven hours and was claimed by the Islamic State.

Mr. Ghani, American officials said, had to show that there was some degree of accountability in his government. But Mr. Ghani, in fact, stepped in to protect the defense minister when Parliament was trying to oust him after the hospital attack.

Gen. John W. Nicholson, the commander of the American-led war effort in Afghanistan, said that while the Islamic State claimed responsibility for the hospital attack in March and the Taliban claimed responsibility for the base attack last week, military officials were watching for “convergence” between the two groups in Afghanistan. The style of attacks, General Nicholson said at a news conference with Mr. Mattis, was similar, and he added that it was “quite possible that Haqqani” was responsible for the base attack last week.

The Afghan president’s office said that Mr. Ghani and Mr. Mattis were meeting ahead of the Trump administration’s decision on whether to increase the number of American troops in Afghanistan, which General Nicholson has asked for. Mr. Mattis said he had not yet decided whether he would recommend a troop increase.