Yahoo! Inc. (Nasdaq: YHOO) and Facebook Inc. (Nasdaq: FB) reached a settlement in a patent dispute, while agreeing to strengthen an alliance between the companies, people with knowledge of the matter said.

Facebook Chief Operating Officer Sheryl Sandberg and Yahoo’s interim chief executive officer, Ross Levinsohn, helped work out the terms, said the people, who asked not to be identified because the matter is private. Boards of both companies have agreed to the deal, one person said.

The agreement includes patent-portfolio cross-licensing, one person said, resolving a dispute kicked off in March, when Yahoo alleged that Facebook infringes patents covering such functions as Internet privacy, advertising and information sharing. Facebook, the largest social-networking service, countersued in April, accusing Yahoo of infringement.

Larry Yu, a spokesman for Facebook, and Sheila Tran, a spokeswoman for Sunnyvale, California-based Yahoo, didn’t immediately respond to phone messages seeking comment.

Yahoo filed the original lawsuit under the leadership of Scott Thompson, who resigned in May amid pressure from investors, after failing to correct misstatements in his academic record. Levinsohn stepped in after Thompson’s departure and is being considered as a permanent CEO, among other candidates, people familiar with the matter have said.

Suit, Countersuit

Yahoo, in the lawsuit filed March 12 in federal court in San Jose, California, sought an order barring Facebook from infringing 10 patents. It also sought triple damages. In the countersuit, Facebook accused Yahoo of infringing 10 patents through its home page and the Flickr-photo sharing service.

An end to the patent dispute may free Facebook from potential challenges the social-network website warned investors about in March.

“If an unfavorable outcome were to occur in this litigation, the impact could be material to our business, financial condition or results of operations,” Facebook, which sold shares in an initial public offering in May, said in a March 27 filing.

The technology blog AllThingsD previously reported the settlement and deeper ties between Yahoo and Facebook.

The advertising alliance could help Yahoo recover some of the revenue that it has been losing as marketers shift more of their spending to a larger and more engaged audience on Facebook’s online social network.

Under Thompson, Yahoo filed the patent lawsuit in March, wielding it as a weapon against a company that Thompson believed had been prospering from the ideas of its older rival. The complaint alleged that Facebook infringed on 10 Yahoo patents covering Internet advertising, privacy controls and social networks. Yahoo Inc. added two more patents to the lawsuit later.

But Thompson’s attack on Facebook Inc. quickly turned into a public-relations disaster. Much of the technology industry railed against Yahoo’s tactics. Critics viewed the lawsuit as a financial shakedown by a desperate company whose well of innovation had run dry.

New York venture capitalist Fred Wilson summed up the enmity toward Yahoo in an acerbic blog post that ended with this denouement: “I am writing this in outrage at Yahoo. I used to care about that company for some reason. No more. They are dead to me. Dead and gone. I hate them now.”

(Bloomberg and The AP contributed to this report.)