Amman, Jordan - Weapons shipped into Jordan by the Central Intelligence Agency and Saudi Arabia intended for Syrian rebels have been systematically stolen by Jordanian intelligence operatives and sold to arms merchants on the black market, according to American and Jordanian officials.

Some of the stolen weapons were used in a shooting in November that killed two Americans and three others at a police training facility in Amman, FBI officials believe after months of investigating the attack, according to people familiar with the investigation.

The existence of the weapons theft, which ended only months ago after complaints by the US and Saudi governments, is being reported for the first time following a joint investigation by Al Jazeera and The New York Times.

The theft, involving millions of dollars of weapons, highlights the messy, unplanned consequences of programmes to arm and train rebels - the kind of programme the CIA and Pentagon have conducted for decades - even after the Obama administration had hoped to keep the training programme in Jordan under tight control.

The Jordanian officers who were part of the scheme reaped a windfall from the weapons sales, using the money to buy expensive SUVs, iPhones and other luxury items, Jordanian officials said.

The theft and resale of the arms - including Kalashnikov assault rifles, mortars and rocket-propelled grenades - have led to a flood of new weapons available on the black arms market.

Investigators do not know what became of most of them, but a disparate collection of groups, including criminal networks and rural Jordanian tribes, use the arms bazaars to build their arsenals. Weapons smugglers also buy weapons in the arms bazaars to ship outside the country.

The FBI investigation into the Amman shooting, run by the bureau’s Washington field office, is continuing.

But American and Jordanian officials said the investigators believed that the weapons that a Jordanian police captain, Anwar Abu Zaid, used to gun down two Jordanians, two American contractors and one South African had originally arrived in Jordan intended for the Syrian rebel-training programme.

The officials said this finding had come from tracing the serial numbers of the weapons.

Mohammad H al-Momani, Jordan's minister of state for media affairs, said allegations that Jordanian intelligence officers had been involved in any weapons thefts were "absolutely incorrect".

"Weapons of our security institutions are concretely tracked, with the highest discipline," he said.

He called the powerful Jordanian intelligence service, known as the General Intelligence Directorate, or GID, "a world-class, reputable institution known for its professional conduct and high degree of cooperation among security agencies". In Jordan, the head of the GID is considered the second most important man after the king.

Representatives of the CIA and FBI declined to comment.

The US State Department did not address the allegations directly, but a spokesman said that the US' relationship with Jordan remained solid.

"The United States deeply values the long history of cooperation and friendship with Jordan," said John Kirby, the spokesman. "We are committed to the security of Jordan and to partnering closely with Jordan to meet common security challenges."

The training programme, which in 2013 began directly arming the rebels under the code name Timber Sycamore, is run by the CIA and several Arab intelligence services and aimed at building up forces opposing President Bashar al-Assad of Syria.

The United States and Saudi Arabia are the biggest contributors, with the Saudis contributing both weapons and large sums of money, and with CIA paramilitary operatives taking the lead in training the rebels to use Kalashnikovs, mortars, antitank guided missiles and other weapons.

The existence of the programme is classified, as are all details about its budget. US officials say that the CIA has trained thousands of rebels in the past three years, and that the fighters made substantial advances on the battlefield against Syrian government forces until Russian military forces - launched last year in support of Assad - compelled them to retreat.

The training programme is based in Jordan because of the country's proximity to the Syrian battlefields. From the beginning, the CIA and the Arab intelligence agencies relied on Jordanian security services to transport the weapons, many bought in bulk in the Balkans and elsewhere around Eastern Europe.

The programme is separate from one that the Pentagon set up to train rebels to combat fighters of the Islamic State of Iraq and the Levant (ISIL, also known as ISIS), rather than the Syrian military. That programme was shut down after it managed to train only a handful of Syrian rebels.

Jordanian and American officials described the weapons theft and subsequent investigation on the condition of anonymity because the Syrian rebel training is classified in the United States and a government secret in Jordan.

News of the weapons theft and eventual crackdown has been circulating inside Jordan's government for several months.

Husam Abdallat, a senior aide to several past Jordanian prime ministers, said that he had heard about the scheme from current Jordanian officials. The GID has some corrupt officers in its ranks, Abdallat said, but added that the institution as a whole was not corrupt.

"The majority of its officers are patriotic and proud Jordanians who are the country's first line of defence," he said.

Jordanian officials who described the operation said it had been run by a group of GID logistics officers with direct access to the weapons once they reached Jordan. The officers regularly siphoned lorryloads of the weapons from the stocks, before delivering the rest of the weapons to designated drop-off points.

Then the officers sold the weapons at several large arms markets in Jordan. The main arms bazaars in Jordan are in Ma'an, in the southern part of the country; in Sahab, outside Amman; and in the Jordan Valley.

It is unclear whether the current head of the GID, General Faisal al-Shoubaki, had knowledge of the theft of the CIA and Saudi weapons. But several Jordanian intelligence officials said senior officers inside the service had knowledge of the weapons scheme and provided cover for the lower-ranking officers.