By Alexei Oreskovic and Diane Bartz

SAN FRANCISCO (Reuters) - Facebook will pay Microsoft Corp $550 million in cash for hundreds of patents recently sold by AOL, the social networking company's latest move to bulk up its intellectual property in the wake of a lawsuit filed by Yahoo.

The deal, shortly before Facebook is expected to have the largest initial public offering in Silicon Valley history, will give the social network 650 patents and patent applications, as well as a license to another 275 patents and applications owned by Microsoft.

Microsoft trumped Amazon, eBay and other tech giants earlier this month with its more than $1 billion purchase of most of AOL Inc. patent trove.

Valuing patents is a complex process, and it was not immediately clear whether Microsoft profited from the deal with Facebook.

Brad Smith, Microsoft's General Counsel, said in a prepared statement on Monday that the Facebook deal allows it "to recoup over half of our costs while achieving our goals from the AOL auction."

Facebook was also a participant in the AOL auction, a source told Reuters at the time.

Facebook's deal with Microsoft comes as the world's No.1 social networking company is preparing for an initial public offering that could value it at up to $100 billion and as Facebook fights a legal battle with Yahoo Inc.

Yahoo sued Facebook earlier this year, alleging that Facebook infringed 10 Yahoo patents, including several that cover online advertising technology. Facebook countersued Yahoo in April, alleging that Yahoo infringes 10 of Facebook's patents.

In March, Facebook acquired 750 patents from International Business Machines Corp.

Microsoft invested $240 million in Facebook in 2007 and the two companies have forged various business collaborations over the years. Facebook features search results from Microsoft's Bing search engine in its social networking service as well as video chat technology provided by Skype, which Microsoft acquired last year.

Netflix Chief Executive Reed Hastings serves on the board of directors of both Facebook and Microsoft.

(Editing by Leslie Gevirtz)