Image caption BP put its stake in TNK-BP up for sale in June

Oil giant BP has agreed to sell its 50% stake in TNK-BP to Russia's Rosneft in return for cash and shares.

The UK firm will get $17.1bn (£10.7bn) cash and a 12.84% stake in Rosneft, enabling BP to continue to share in Russia's vast energy resources.

BP has agreed to eventually use some of the cash to buy further Rosneft shares, taking its stake to 19.75%.

Rosneft is also buying the other half of TNK-BP from the AAR consortium of Russian billionaires for $28bn.

Companies active in Russia's energy sector have come under political pressure in the past.

However, this deal has the blessing of the Russian President Vladimir Putin, who said state-controlled Rosneft had made a good deal at a good price: "This is a good, large deal that is necessary, not only for the Russian energy sector but also the entire economy."

Lucrative venture

The acquisition of the stake in TNK-BP, one of Russia's biggest oil firms, will give Rosneft about half of Russia's energy sector and make it the world's largest publicly-traded oil group.

BP said that once the proposed transaction gets the necessary shareholder and regulatory approval, it will use $4.8bn of the cash received on buying a further 5.66% of Rosneft shares. BP already holds 1.25% of Rosneft.

Although BP's involvement in the Russian joint venture has been lucrative, paying billions of dollars in dividends to the UK company, relations with its partners have often been fraught with disagreement.

In 2011, the AAR consortium attempted to block a drilling joint venture in the Arctic between BP and Rosneft through the courts.

The plan was eventually dropped.

As well as internal wrangles, BP employees at TNK-BP have fallen foul of Russian authorities.

While serving as head of TNK-BP, Bob Dudley - now the head of BP as a whole - had his office bugged and raided by the police and met with onerous back-tax demands, legal action and visa problems.

He eventually fled the country in 2008.

A tie-up with Rosneft would keep BP in Russia, allowing it to continue to explore and exploit the country's vast energy resources, including in the Arctic region. Rosneft would be able to tap into BP's expertise in exploring in difficult and potentially hazardous conditions.

Rosneft said it would have two BP representatives on its board and that it would "benefit from BP's significant experience and successful track-record of applying best international practices in Russia".