By Jonathan Stempel and Suzanne Barlyn

NEW YORK (Reuters) - American International Group Inc <AIG.N> has agreed to pay roughly $10.2 billion to Warren Buffett's Berkshire Hathaway Inc <BRKa.N> to take on many long-term risks on U.S. commercial insurance policies it has already written.

The reinsurance transaction covers "long-tail" exposures, which are liabilities that emerge long after policies are issued, from excess casualty, workers compensation and other AIG policies issued before last year.

Berkshire's National Indemnity Co unit, led by Buffett's reinsurance chief Ajit Jain, will take on 80 percent of net losses in excess of the first $25 billion, with a maximum liability of $20 billion.

AIG said the payment comprises $9.8 billion plus interest since Jan. 1, 2016, and will be made by June 30.

The transaction helps AIG Chief Executive Peter Hancock lower risk at his New York-based insurer, which has reduced exposures and shed businesses since its 2008 federal bailout, and frees up capital for share buybacks.

"This decisive step enables us to focus firmly on the future," with "additional risk capacity to serve our clients and return capital to shareholders," Hancock said in a statement.

For Buffett, the transaction boosts how much his Omaha, Nebraska-based conglomerate can invest, including stocks and whole companies.

Berkshire's float, which helps fund growth and reflects the premiums collected upfront before claims are paid, totaled $91 billion on Sept. 30.

In a research note, Barclays Capital analyst Jay Gelb said the transaction's long-term economics should be "attractive" for Berkshire.

But Gelb and UBS analyst Brian Meredith said the transaction may signal lingering problems in AIG's portfolio, even after a $3.6 billion charge in late 2015.

"This announcement indicates that there may be more pain left," wrote Meredith, who rates AIG "neutral." Gelb rates it "overweight."

Berkshire did not respond to requests for comment.

AIG plans to take a charge in the just-completed quarter for the transaction. It said it would have recognized a $2.9 billion loss had the transaction occurred a year ago.

The payment to Berkshire represents nearly 3 percent of AIG's investment portfolio.

AIG will retain authority to handle and resolve claims, similar to an arrangement that Hartford Financial Services Group Inc <HIG.N> struck when it passed some asbestos liabilities to National Indemnity this month.

National Indemnity in 2014 reached a similar reinsurance transaction with Liberty Mutual covering $6.5 billion of liabilities, but took responsibility for resolving asbestos and environmental claims.

In afternoon trading, AIG shares rose 13 cents to $66.42, while Berkshire Class A shares rose $690 to $239,550.

(Reporting by Suzanne Barlyn and Jonathan Stempel in New York, and Richa Naidu and Nikhil Subba in Bengaluru; Editing by Marguerita Choy and Andrew Hay)