The firms reach agreement on Facebook's insistence on a virtual currency for developers. Zynga, which has several popular apps on the social network, had threatened to take its games elsewhere.

Facebook Inc. and Zynga Game Network Inc. ended weeks of tense negotiations by agreeing Tuesday to a five-year deal to keep Zynga's social games on the social network.

The agreement between the Bay Area companies officially puts an end to a high-stakes game of corporate poker, one that involved tens of millions of dollars.

At issue is a virtual currency Facebook wants all developers on its platform to use in any online commerce, with Facebook taking a cut of all sales. Zynga — which created Farmville, Mafia Wars and several of the most popular apps on Facebook — threatened to start taking its games elsewhere.

In a joint statement, Zynga's chief executive, Mark Pincus, and Facebook's chief operating officer, Sheryl Sandberg, said Zynga is "testing Facebook Credits in select games and will expand to more titles over the coming months."

They declined to say how much of each sale Zynga would get to keep and, conversely, what Facebook's cut would be. In similar models, such as Apple Inc.'s iTunes and Microsoft Corp.'s Xbox Live, the owner of the platform typically takes a 30% cut, with developers receiving 70% of all transactions.

Estimates of the annual revenue for Zynga, which does not reveal its finances, range from $240 million to $600 million, according to Jeremy Liew, managing director of Lightspeed Venture Partners. Most but not all of Zynga's revenue comes from its games on Facebook.