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

Italy, stuck in recession, hopes the fair will be a big money-spinner. Ten million tickets have been sold already for the six-month event.
But shortly after the opening, protesters in Milan clashed with police, who responded with tear gas.
Representatives of 145 countries are in the city for the fair, which boasts 54 national pavilions at a sprawling site.
The food theme focuses on nutrition and combating hunger globally. But it is also a showcase for Italian cuisine.
The exhibition has already been marred by scandal after several officials in the organising body were arrested for corruption.
And violence broke out on Friday as dozens of people protesting against the Expo torched cars and broke shops windows.
Some groups have criticised the fair, calling it a symbol of big business interests, and held protests.
There was an anti-globalisation march by students in Milan on Thursday.
Pope Francis, who spoke via a televised link-up to the opening ceremony, said he wanted every person who visited the Expo to think of the "faces of millions of people who are hungry today".
Meanwhile Italian Prime Minister Matteo Renzi said: "Today it is as though Italy is embracing the world."
Italy hopes the fair, covering a one million sq m (10.7m sq ft) site, will attract some 20 million visitors and generate revenues of about $10bn (Â£5.6bn; â‚¬8.9bn).
Oil giant BP has agreed to sell its 50% stake in TNK-BP to Russia's Rosneft in return for cash and shares.
[NEXT_CONCEPT]
A major global commercial fair - Milan Expo 2015 - has opened in northern Italy with food as the theme.