ATAQ, Yemen — A military coalition led by Saudi Arabia and backed by the United States has cut secret deals with al Qaeda fighters, paying some to leave key cities and towns the militants had seized across Yemen and letting others retreat with weapons, equipment and wads of looted cash, an investigation by the Associated Press has found. Hundreds more were recruited to join the coalition itself.

Again and again over the past two years, the coalition has claimed to win decisive victories that drove al Qaeda militants from their strongholds and shattered their ability to attack the West. What the victors didn’t disclose: many of those conquests came without firing a shot.

The compromises and alliances have allowed al Qaida militants to survive to fight another day — and risk strengthening the most dangerous branch of the terror network that carried out the Sept. 11 attacks.

Key participants in the pacts said the U.S. was aware of the arrangements and held off on any drone strikes as the al Qaeda fighters retreated in plain sight.

The AP’s findings are based on reporting in Yemen and interviews with two dozen officials, including Yemeni security officers, militia commanders, tribal mediators and four members of al Qaida’s branch. All but a few of those sources spoke on condition of anonymity, fearing reprisals.

The deals uncovered by the AP reflect the contradictory interests of the two wars being waged simultaneously in this southwestern corner of the Arabian Peninsula.

In one conflict, the U.S. is working with its Arab allies with the aim of eliminating the extremists known as al Qaeda in the Arabian Peninsula, or AQAP. But the larger mission is to win the civil war against the Houthis, Iranian-backed Shiite rebels. In that fight, al Qaeda is effectively on the same side as the coalition — and, by extension, the United States.

The U.S. has sent the coalition billions of dollars in weapons to fight the Houthis, and American jets provide air-to-air refueling for coalition war planes. The U.S. does not fund the coalition, however, and there is no evidence that American money went to AQAP militants.

“Elements of the U.S. military are clearly aware that much of what the U.S. is doing in Yemen is aiding AQAP and there is much angst about that,” said Michael Horton, a fellow at the Jamestown Foundation, a U.S. analysis group that tracks terrorism. But supporting allies against “what the U.S. views as Iranian expansionism takes priority over battling AQAP and even stabilizing Yemen,” Horton said.