From beer to beans to beds: Whitbread's long history
1742 - Samuel Whitbread forms partnership with Godfrey and Thomas Shewell
1750 - Whitbread creates UK's first mass-production brewery in London
1868 - Begins producing beer in bottles
1968 - Starts brewing Heineken under licence
1974 - Opens first Beefeater steakhouse
1990s - Buys David Lloyd Leisure, Marriott Hotels, TGI Fridays, Pizza Hut, Premier Lodge
1995 - Buys Costa Coffee from Sergio and Bruno Costa for £19m when it had 39 outlets
2000 - Sells brewing business to focus on Premier Inn and Costa
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.
Analysis: Dominic O'Connell, Today business presenter
For years, demerger was a dirty word at Whitbread. When asked, as they often were, about the logic of having a hotel chain and a coffee chain in the same company, executives would extol the benefits of having two leisure brands under one roof.
Shareholders were always less convinced, but were happy to go along with the idea while Whitbread grew its revenue, profits and share price at a steady clip over the last decade.
All that changed with the arrival of Alison Brittain as chief executive - and the appearance on the shareholder register of Elliott Management, an aggressive, deep-pocketed US hedge fund with a track record of shaking up big companies. It pushed hard for a demerger, and Ms Brittain, who judged that Costa and Premier had reached sufficient scale to stand on their own feet, opened the door.
The plan was that Costa would be spun off at some time in the next two years, but Coca-Cola pre-empted that with a knockout offer.
While this is a landmark deal for Whitbread, it is also a significant move for Coca-Cola, taking it into hot beverages for the first time and, it hopes, providing the growth for which its investors have been crying out.
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."