When contacted separately by telephone on Saturday, Sergeant Melgar’s widow, Michelle, and his brother, Shawn, declined to comment.

Lawmakers have criticized top officers and Pentagon officials for offering a shifting timeline of the events in the Niger attack, and for failing to respond with timely, accurate information about the American military’s role on the continent at a time when President Trump has loosened restrictions on the armed forces to intensify attacks against the Islamic State and Al Qaeda around the world.

Sergeant Melgar, a graduate of Texas Tech University who joined the Army in 2012, was assigned to the 3rd Special Forces Group, based at Fort Bragg, N.C., the same unit whose soldiers were attacked by a much larger and heavily armed group of Islamic State fighters near the border between Niger and Mali on Oct. 4.

According to military officials, Sergeant Melgar was part of a small team in Bamako assigned to help provide intelligence about Islamic militancies in Mali to the United States ambassador there, Paul A. Folmsbee, to protect American personnel against attacks. The sergeant also helped assess which Malian Army troops might be trained and equipped to build a counterterrorism force.

Sergeant Melgar, a native of Lubbock, Tex., was about four months into what military officials said was a six-month tour in Mali, and was living with three other American Special Operations troops in a house provided by the American Embassy.

Two of those housemates were members of the Navy’s SEAL Team 6, which has over the past decade carried out kill-or-capture missions in Libya, Yemen, Afghanistan, Iraq and Somalia, as well as the one that killed bin Laden in Abbottabad, Pakistan, in 2011.

According to two senior American military officials, the two SEAL commandos were in Mali with the approval of Mr. Folmsbee in a previously undisclosed and unusual clandestine mission to support French and Malian counterterrorism forces battling Al Qaeda’s branch in North and West Africa, known as Al Qaeda in the Islamic Maghreb, as well as smaller cells aligned with Al Qaeda or the Islamic State. The Americans helped provide intelligence for missions, and had participated in at least two such operations in Mali this year before Sergeant Melgar’s death.