The botched military operation in Yemen that killed a US Navy SEAL and over a dozen al Qaeda terrorists and civilians had been in the works for months before President Trump approved it shortly after taking office, according to a published report.

In the waning months of his presidency, Barack Obama was hashing out with the Pentagon the Yemen attack plan that was aimed at gathering intelligence on al Qaeda for future strikes against the jihadist group to wipe them out, CNN said.

Obama administration officials cited “operational reasons” for pushing back the date of the raid for sometime after Jan. 20, leaving it in the hands of the newly minted president to determine its course, CNN reported.

One aspect of the plan that gave Obama pause was the need for a moonless night so the SEALs would be camouflaged by the cover of night, as they were during Saturday’s raid on the al Qaeda headquarters in the town of Al Bayda, the network said.

Trump greenlighted the operation almost immediately after taking the oath of office.

US military officials on Wednesday announced they were investigating the raid that claimed the life of Chief Special Warfare Operator William “Ryan” Owens and “likely” killed civilians.

About 30 people, including 10 women and children, also were killed, according to media reports.

The SEALs and a United Arab Emirates special forces team were spotted by the terrorists as they approached the compound, sparking the firefight on the ground, CNN said.

After the SEALs called for aerial support, military aircraft flew in and opened fire, likely causing the civilian casualties, CNN said.

The civilian victims were “caught up in aerial gunfire that was called in to assist US forces in contact against a determined enemy that included armed women firing from prepared fighting positions, and US special operations members receiving fire from all sides,” the Pentagon said in a statement.

“The raid resulted in the seizure of materials and information that is yielding valuable intelligence to help partner nations deter and prevent future terror attacks in Yemen and across the world,” the statement said.

Fourteen al Qaeda fighters were killed in the battle.