The Environmental Protection Agency said that BP "agreed to safety and ethics improvements" in exchange for removing the ban, which had hurt the British company's ability to do business in the United States.
The five-year deal with the EPA will allow BP to pursue new oil exploration leases in deepwater tracts in the Gulf of Mexico, which still bears many traces of the massive 2010 spill, the worst in US history.
"After a lengthy negotiation, BP is pleased to have reached this resolution, which we believe to be fair and reasonable," BP America chairman and president John Minge said.
"Today's agreement will allow America's largest energy investor to compete again for federal contracts and leases."
Under the deal, BP must add and expand efforts in corporate ethics and compliance, enforce a detailed code of conduct, and meet EPA audit requirements.
It also must protect company employees who report violations and incentivize employees to pursue safety and compliance standards in their compensation agreements.
In return, BP will withdraw its own August 2013 lawsuit against the EPA that contested the agency's authority to apply the sweeping ban.
Craig Hooks, assistant administrator for EPA's Office of Administration and Resources Management, hailed the "fair agreement that requires BP to improve its practices in order to meet the terms we've outlined together."
- Major Pentagon supplier -
The EPA set the ban on BP getting government contracts on November 28, 2012, citing the oil giant's "lack of business integrity" in the spill and its aftermath.
Eleven people were killed and some 4.9 million barrels of oil flooded into the gulf after the Deepwater Horizon drilling rig exploded and sank.
The EPA had said the ban would continue "until the company can provide sufficient evidence to EPA demonstrating that it meets federal business standards."
In pleading guilty for the spill, BP agreed to pay the government $4.5 billion to settle criminal charges in the case.
It also agreed earlier in 2012 to settle damage claims by businesses and individuals for about $7.8 billion.
BP is the Pentagon's main supplier of fuel, both in the United States and abroad.
Current contracts were not affected by the EPA's decision, but the exclusion of federal contracts prevented BP from obtaining new oil exploration leases from the government in the Gulf of Mexico.
The company says it is the main producer of deepwater oil and gas in the gulf, as far as government leases are concerned.
BP's US activities account for 30 percent of its pre-tax earnings, and the United States is responsible for a fifth of its global oil and gas production.
In an effort to stem potential future losses, BP had filed a lawsuit in Texas federal court against the EPA, saying it had paid sufficient fines over the Deepwater Horizon explosion.
But in light of the agreement with the agency, BP accepted to drop the lawsuit.
It also promised to implement a set of safety and operations, ethics and compliance, and corporate governance requirements in line with standard practices demanded by US authorities.
BP will namely hire an independent auditor during the five years of the accord to examine its practices.
The spill hit the oil group's earnings for several quarters despite reserves set aside to respond to numerous claims for damages, including a $7.8 billion deal reached with thousands of victims.