President Hamid Karzai had made the fate of the detention center north of Kabul part of his ill-tempered push to regain sovereignty over key matters from the Americans, ahead of next year's pullout of foreign combat troops.
The US was long concerned a total handover to Afghanistan's weak and corruption-prone security forces would allow suspected Taliban and al-Qaeda militants housed at Bagram to return to the battlefield.
But US Defense Secretary Chuck Hagel clinched an agreement with Karzai in a telephone call on Saturday, and the handover ceremony took place on Monday.
"The transfer of the detention facility is an important part of the overall transition of security," General Joseph Dunford, commander of the international coalition in Afghanistan, said in a statement.
"This ceremony highlights an increasingly confident, capable and sovereign Afghanistan."
Dunford and Defence Minister Bismillah Mohammadi signed a deal guaranteeing "the lawful and humane treatment of detainees and their intention to protect the people of Afghanistan and coalition forces", the statement said.
Bagram was due to be turned over to Afghan forces on March 9, but the transfer was postponed at the last minute after Karzai indicated "innocent" prisoners held there would be released.
In September, the US gave Afghan authorities control over more than 3,000 detainees at Bagram, once dubbed the Guantanamo Bay of Afghanistan because some inmates are detained without trial or knowledge of any charges.
But the Americans continued to guard 50 foreigners not covered by the agreement, as well as hundreds of Afghans arrested since a transfer deal was first signed in March 2012.
Their extended control sparked angry comments from Karzai and a warning from Afghanistan's top Islamic body that the US military was coming to be seen as an "occupation" force as it battles a long-running Taliban insurgency.