SAN FRANCISCO – Facebook and Yahoo have agreed to settle a patent dispute, averting a potentially lengthy battle over the technology running two of the Internet’s most popular destinations.

In dropping the lawsuits, the companies agreed to license their patents to each other. They are also agreeing to an advertising alliance that expands their existing partnership.

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.

Friday’s settlement involves no exchange of money and comes after a months-long patent squabble.

The truce ends a conflict provoked by Yahoo’s short-lived CEO, Scott Thompson, who was dumped from the job two months ago after misinformation on his biography raised questions about his integrity.

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.”

When Yahoo replaced Thompson in May with interim CEO Ross Levinsohn, it opened the door for the company to settle the dispute under a reshuffled board of directors. Six of Yahoo’s 11 directors joined the board after Yahoo sued Facebook on March 12.

Yahoo’s legal assault had exposed Facebook’s vulnerability to patent claims as it prepared to complete the biggest initial public offering of stock by an Internet company.

Facebook insulated itself by buying 750 patents from IBM Corp. and spending $550 million to acquire an additional 650 patents that one of its biggest shareholders, Microsoft Corp., had purchased from AOL Inc. Armed with its own arsenal of intellectual property, Facebook signaled that it wasn’t backing down and filed its own lawsuit against Yahoo in April for patent infringement.

Facebook’s stock gained 26 cents to close Friday at $31.73. Yahoo’s stock dipped 7 cents to close at $15.78.