Coca-Cola is to buy the Costa coffee chain from owner Whitbread in a deal worth £3.9bn.

Whitbread had intended to spin off the chain as a separate firm, but said a straight sale was more profitable.

Chief executive Alison Brittain said Whitbread would now focus on its Premier Inn business in the UK and Germany.

Whitbread bought Costa, which is now the UK's biggest coffee chain, for just £19m in 1995.

At the time, it had just 39 outlets. It now has more than 2,400 UK coffee shops, as well as some 1,400 outlets in 31 overseas markets. Costa Express has 8,237 vending machines worldwide.

Whitbread shares rose more than 17% in early Friday trading.

Speaking on the BBC's Today programme, Ms Brittain explained that Coca-Cola wanted to buy Costa because "they want the coffee product, they have no coffee in their range".

She said the money from the sale would be used to expand the Premier Inn chain, return some cash to shareholders, pay down debt and boost the pension fund.

Describing the sale as a "win-win" for everyone, she said the price paid by Coca-Cola was far higher than if Costa had been demerged into a stand-alone company on the stock market.

She said she thought the beverage giant would use Costa to create "ready to drink, cold brew coffees".

"You could see Costa absolutely everywhere, in vending machines, hotels, restaurants, pubs, cafes - in all the places you see Coke today," she added.

Whitbread announced earlier this year that it was planning to spin off Costa.

Whitbread had been under pressure to consider a break-up of the business after hedge fund Elliott Advisors became the company's largest shareholder.

Elliott reportedly put forward a demerger plan after building up a 6% stake in the firm.

As well as being the largest UK coffee chain, Costa is also the world's second largest. It is looking to triple its presence in China, where it is second to Starbucks.

According to consumer analysts Kantar Worldpanel, the out-of-home coffee market is worth £6.3bn a year in the UK alone.

Whitbread also owns restaurants Beefeater and Brewers Fayre. Over the years, it has owned well-known brands such as TGI Fridays, Pizza Hut and Marriott Hotels.

The deal is subject to the agreement of Whitbread's shareholders and various other approvals, including from anti-trust regulators.

It is expected to complete in the first half of next year.

Nicholas Hyett, equity analyst at Hargreaves Lansdown, described the deal as "a bitter-sweet moment for Whitbread investors".

"On the one hand, £3.9bn is an undeniably rich valuation and likely far better than Costa could achieve as an independently listed company, valuing its earnings higher than those of the mighty Starbucks," he said.

"On the other, Costa has long been the jewel in Whitbread's crown and some will be sad to see it go at any price, especially given the growth potential in China and elsewhere."