LONDON — As consumers shy away more and more from sugary soft drinks, Coca-Cola is betting on a new way to cater to them: Serve them coffee.

The American beverage titan said on Friday that it planned to buy Costa, one of the world’s biggest coffee chains, for 3.9 billion pounds, or $5.1 billion, in cash.

The deal — Coke’s biggest-ever acquisition of a brand, surpassing its 2007 takeover of Vitaminwater — shows just how much the company is willing to spend to keep up with changing tastes. The takeover will give it the third-largest player in the coffee shop industry, well behind Starbucks and just behind McDonald’s.

But Coke’s latest bid will also plunge the company deep into a war over coffee consumption, in all its forms, that’s being waged by a pair of food giants.