The Federal Reserve finally has wiped its hands clean of AIG and turned a nearly $18 billion profit for taxpayers in the process.

Now it's up to the Treasury Department to sell the rest of the U.S. government's stake in the insurance giant.

The Federal Reserve Bank of New York announced Thursday that it had sold the last of its securities related to the AIG (AIG) bailout. The portfolio, known as Maiden Lane III, consisted of collateralized debt obligations, or CDOs -- highly complex financial instruments that bundle various kinds of debt. The Maiden Lane III sales earned $6.6 billion.

Months earlier, the New York Fed sold off Maiden Lane II assets for $2.8 billion. That portfolio contained mortgage-backed securities insured by AIG. The NY Fed also made $8.2 billion in interest and fees from a credit line extended to AIG that was terminated last year.

AIG's bad bets crippled the insurer in 2008. The company played a major role in the financial crisis that ensued. In an unprecedented move, the government swooped in, buying many of the toxic assets.

Related: Treasury to sell more AIG shares

"The completion of the sale of the Maiden Lane III portfolio marks the end of an important chapter -- our assistance to AIG -- that was undertaken to stabilize the financial system in the midst of the financial crisis," William Dudley, president of the New York Fed, said in a press release.

That said, the U.S. government is not entirely free of AIG. The Treasury Department still owns $29 billion, or roughly 53% of AIG's common stock.

The Treasury Department has said it too expects to make a profit on that investment, as it sells the shares over time.