American International Group Inc , the insurer that received $180 billion of federal bailouts, posted its first profit in seven quarters on Friday, sending its shares up 9 percent in premarket trade.

Second-quarter net earnings were $1.8 billion, or $2.30 a share, compared with a net loss of $5.4 billion, or $41.13 a share, a year earlier.

After dividends on preferred stock held by the federal government, profit attributable to common shareholders was $311 million.

On an adjusted basis, the company earned $2.57 a share, far above analysts' average forecast of $1.33, according to Reuters Estimates.

AIG shares were up $2.13 at $24.66 in premarket trading.

Once the world's largest insurer, AIG nearly collapsed last year because of its exposure to credit default swaps, which left it on the hook for tens of billions of dollars of payouts.

The latest results included $5.7 billion in unrealized gains on investments and from the adoption of new accounting rules.

Our results reflect stabilization in certain of our businesses, Chief Executive Ed Liddy said in a statement. But other operations, including its main insurance business, remained challenged, largely driven by weak economic conditions and the lingering effect of the negative AIG events earlier in the year, he said.

The company's general insurance operations posted operating income, which excludes net realized capital gains, of $1 billion, down from $1.7 billion a year earlier.

Net written premiums fell 19 percent to $7.9 billion.

(Reporting by Lilla Zuill; Editing by Derek Caney and John Wallace)