Updated

NEW YORK -- As the Gulf oil spill gushed out of control, BP's financial liabilities seemed big enough to sink the company. No more.

Cleanup, government fines, lawsuits, legal fees and damage claims will likely exceed the $40 billion that BP has publicly estimated, according to an Associated Press analysis. But they'll be far below the highest estimates made over the summer by legal experts and prominent Wall Street banks, such as Goldman Sachs, which said costs could near $200 billion.

BP will survive the worst oil spill in U.S. history for several key reasons: it has little debt; its global businesses are forecast to generate $26 billion next year in cash flow from operations; the environmental impact of the spill isn't as bad as feared; and the government seems unlikely to ban BP from Gulf drilling. To bolster its finances, BP has cut its dividend, issued debt and sold more than $21 billion in assets.

"It could have been a lot worse," says Tyler Priest, a University of Houston petroleum historian who serves on President Obama's oil spill investigation committee. "BP is going to come back from this."

Many influential investors appear to agree. According to Thomson Reuters, 23 firms with $1 billion or more invested in the stock market, including BlackRock Investment Management, Managed Account Advisors and Rydex Security Global Investors, more than doubled their holdings of BP stock from July through September.

At $44.11, BP's stock price has risen 63 percent from its low of $27.02 on June 25. It's still down 27 percent from its close of $60.48 on April 20, the day of the spill. The well was capped on July 15.

The AP analysis shows the company is likely to face $38 billion to $60 billion in spill-related costs. A settlement with the federal government could reduce that amount, while a successful class-action lawsuit could add billions more.

The analysis includes:

--The $10.7 billion that BP already has paid to plug its well, clean up the spilled oil and pay damage claims and other costs.

--A $20 billion fund that BP set up in August for individuals and private businesses that were affected by the spill. The fund, known as the Gulf Coast Claims Facility, pays for environmental damage, personal injury, cleanup and lost earnings. The fund so far has paid $2.7 billion to address nearly 168,000 claims. Nearly half a million individuals and businesses have filed claims, and those that settle with the fund give up their right to sue the company. If any of the $20 billion is left over, it goes back to BP.

--Fines: The Justice Department is suing BP for violating the Clean Water Act. Fines are based on how much oil was spilled. The government's estimate of 4.9 million barrels means BP faces between $5.4 billion and $21.1 billion in fines. The upper limit applies if investigators conclude BP acted with gross negligence. The government has a history of settling with companies for as little as 50 cents on the dollar in order to avoid lengthy disputes, says Eric Schaeffer, former head of the Environmental Protection Agency's enforcement division.

-- Legal fees: BP has hired lawyers, engineers and geologists to defend the company. These experts could cost as much as $2 billion, according to Mitratech Inc., a consulting firm that handles legal and trial logistics for Fortune 500 companies.

-- Lawsuits: The toughest costs to estimate are future settlements and judgments from the hundreds of lawsuits filed against BP, including any class actions. Shrimpers, oystermen, charter-boat operators, restaurant workers and real-estate developers are suing BP for lost business. Oil rig workers and cleanup crews are making personal injury claims. And Gulf states and local governments are expected to sue for lost tax revenue and environmental damages. Alabama is seeking an initial $148 million from BP. Analysts at Citigroup say settlements, judgments and punitive damages from these suits will total as much as $6 billion.

Legal experts caution that the unpredictability of juries makes it difficult to estimate the cost of losing a class-action lawsuit. A successful class-action could easily double the Citigroup estimate for total legal liabilities, says Alexandra Lahav, a University of Connecticut professor who studies such lawsuits.

BP may be able to spread the spill's costs around. Minority partners Anadarko Petroleum Corp. and MOEX 2007 LLC own 35 percent of the operation, and rig owner Transocean Ltd. also may be asked to pay. "Companies have the incentive to settle with BP to put the matter behind them," FBR analyst Robert MacKenzie says. He expects BP to get as much as $2 billion from Transocean and as much as $4 billion from Anadarko.

Since the spill, BP has moved aggressively to shore up its finances.

The company suspended its quarterly dividend of 84 cents a share, which cost it $10.5 billion last year. It also raised $21 billion in asset sales that include: $7 billion for its stake in Pan American Energy; $7 billion for oil fields in the U.S., Canada and Egypt; $1.9 billion for its Colombian exploration business; and $1.8 billion for assets in Vietnam and Venezuela. BP also raised $3.5 billion in an Oct. 1. bond sale.

From April through June, when BP's stock was tanking, Fred Fromm, who manages a natural resources fund for Franklin Templeton Investments, scooped up 170,000 shares. Their value climbed by more than $2 million in the third quarter.

A few weeks after the Deepwater Horizon rig exploded and sank, scientists worried the oil slick would reach the Gulf's Loop Current, which sweeps around Florida and up the East Coast. Beaches would be damaged along the way. But BP got lucky. Gulf winds kept shifting, which kept the oil concentrated in the waters south of Louisiana, said David Hollander, a University of South Florida chemical oceanographer. And hurricanes mostly avoided the region.

Scientists disagree about how much oil remains in the Gulf, but already the streaky sheens of oil on the surface are mostly gone. The more oil that remains, the greater the potential for environmental lawsuits.

Whatever remains, "it won't impact their long-term ability to do business," says Citigroup oil analyst Mark Fletcher.

Exxon dealt with lawsuits for decades after its Valdez supertanker ran aground and spilled 11 million gallons of crude into Alaska's Prince William Sound in 1989. The spill cost Exxon $4.5 billion -- nearly half of which went to clean up the oil. The rest was spent on payments to residents and businesses, punitive damages and settlements with the government.

Exxon never lost its perch among industry leaders, and BP won't either, says Citigroup's Fletcher. BP remains among the top oil drillers in a world that runs on petroleum, and that may be the best way to judge the company's lasting power.

"Did (Valdez) stop anyone from buying Exxon gasoline? No. Exxon's results are better than anyone's on a multiyear basis," Fletcher said.