What the plea deal approved by U.S. District Judge Sarah Vance doesn't resolve, though, is the federal government's civil claims against BP. The company could pay billions more for environmental damage from its 2010 spill.
Vance noted that the company already has racked up more than $24 billion in spill-related expenses and has estimated it will pay a total of $42 billion to fully resolve its liability for the disaster in the Gulf of Mexico.
The judge said the $4 billion criminal settlement is "just punishment" for BP, even though the company could have paid far more without going broke. In accepting the deal, Vance also cited the risk that a trial could result in a much lower fine for BP, one potentially capped by law at $8.2 million.
The criminal settlement calls for BP to pay nearly $1.3 billion in fines. The largest previous corporate criminal penalty assessed by the Justice Department was a $1.2 billion fine against drug maker Pfizer in 2009.
The plea deal also includes payments of nearly $2.4 billion to the National Fish and Wildlife Foundation and $350 million to the National Academy of Sciences. The two groups will administer the money to fund Gulf restoration and oil spill prevention projects.
The $4 billion in total penalties are 160 times greater than the $25 million fine that Exxon paid for the 1989 Valdez spill in Alaska, Vance noted.
Before she ruled, the judge heard an apology from a BP executive and emotional testimony from relatives of the 11 workers who died when BP's blown-out Macondo well triggered an explosion on the rig and started the spill.
"I've heard and I truly understand your feelings and the losses you suffered," Vance told the family members.
Keith Jones, whose 28-year-old son, Gordon, died in the rig explosion, said $4 billion isn't adequate punishment.
"It is petty cash to BP," he told Vance. "Their stock went up after this plea deal was announced."
Billy Anderson, whose 35-year-old son, Jason, died in the blast, recalled the trauma of watching the disaster play out on television.
"These men suffered a horrendous death," he said. "They were basically cremated alive and not at their choice."
BP agreed in November to plead guilty to charges involving the workers' deaths and for lying to Congress about the size of the spill from its broken well, which spewed more than 200 million gallons of oil. Much of it ended up in the Gulf and soiled the shorelines of several states. The company could have withdrawn from the agreement if Vance had rejected it.
BP America vice-president Luke Keller apologized to the relatives of the workers who died and for the spill's environmental damage to the Gulf Coast.
"BP knows there is nothing we can say to diminish their loss," he said. "The lives lost and those forever changed will stay with us. We are truly sorry."
Most of the families of rig workers who were killed or injured in the explosion already have settled their claims against BP, through a process separate from this plea deal.
Courtney Kemp-Robertson, whose 27-year-old husband, Roy Wyatt Kemp, died on the rig, said workers had referred to it as the "well from hell" before the explosion.
"By cutting corners, they gambled with the lives of 126 crew members to save a few dollars," she told the judge before turning to address Keller. "They gambled and you lost."
A series of government investigations have blamed the April 20, 2010, blowout on time-saving, cost-cutting decisions by BP and its partners on the drilling project.
Vance told victims' relatives who were in court that she read their "truly gut-wrenching" written statements and factored their words into her decision. She also said she believes BP executives should have personally apologized to family members long before Tuesday's hearing.
"I think BP should have done that out of basic humanity," she said.
BP also has separately agreed to a settlement with lawyers for Gulf Coast residents and businesses who claim the spill cost them money. BP estimates the deal with private attorneys will cost the company roughly $7.8 billion.
In a court filing before the hearing, attorneys for BP and the Justice Department argued that the plea agreement imposes "severe corporate punishment" and will deter BP and other deep-water drilling companies from allowing another disaster to occur.
The Justice Department has reached a separate settlement with rig owner Transocean Ltd. that resolves the government's civil and criminal claims over the Swiss-based company's role in the disaster.
Transocean agreed to plead guilty to a misdemeanour charge of violating the Clean Water Act and pay $1.4 billion in civil and criminal penalties. U.S. District Judge Jane Triche Milazzo has scheduled a Feb. 14 hearing to decide whether to accept that criminal settlement. A different judge will decide whether to accept Transocean's civil settlement.
Many relatives of rig workers who died in the blast submitted written statements that were critical of BP's deal. Vance, however, said she couldn't get involved in plea negotiations and only could impose a sentence that adheres to the agreed-upon terms if she accepted it.
In other criminal cases, four current or former BP employees have been indicted. BP rig supervisors Robert Kaluza and Donald Vidrine are charged with manslaughter, accused of repeatedly disregarding abnormal high-pressure readings that should have been glaring indications of trouble just before the blowout.
David Rainey, BP's former vice-president of exploration for the Gulf of Mexico, was charged with withholding information from Congress about the amount of oil that was gushing from the well.
Former BP engineer Kurt Mix was charged with deleting text messages about the company's spill response.