It is the social networking giant's biggest acquisition to date.
WhatsApp has more than 450 million monthly users and is popular with people looking to avoid text messaging charges.
In a statement announcing the deal, Facebook founder Mark Zuckerberg described WhatsApp's services as "incredibly valuable".
WhatsApp allows users to send messages over internet connections, avoiding text messaging fees. The company claims it is currently registering one million new users a day.
It makes money by charging users a subscription fee of $1 per year, although it offers a free model as well.
Mike Butcher, techcrunch.com, explained why Facebook would want to buy WhatsApp
Silicon Valley's newest billionaires
The deal to buy it includes $4bn in cash and approximately $12 billion worth of Facebook shares, plus an additional $3 billion in stock to WhatsApp's founders and employees at a later date.
On a conference call to discuss the deal, WhatsApp co-founder Jan Koum said he planned to operate the firm "independently and autonomously". He will also become a member of Facebook's board of directors.
"We're excited and honoured to partner with Mark and Facebook as we continue to bring our product to more people around the world," Mr Koum said in a statement.
Mr Zuckerberg said the prospect of a deal was first floated just 11 days ago.
The Facebook founder said he believed WhatsApp was on track to have a billion users, but insisted he had no plans to place advertising on WhatsApp's interface, saying he did not think ads were the best way to make money from messaging systems.
Once the deal is finalised, Mr Koum and co-founder Brian Acton are set to become Silicon Valley's newest billionaires.
WhatsApp has around 50 employees in total.
Cathy Boyle, a senior analyst at research firm eMarketer, said WhatsApp was valuable to Facebook for several reasons beyond advertising, including its younger user base and its popularity overseas.
"WhatsApp actually has greater penetration in a lot of international markets than Facebook," Ms Boyle told the BBC.
She added that it was notable that Facebook's chief financial officer David Ebersman referred to the telecommunications industry when discussing the firm's purchase.
"WhatsApp is trying to siphon the billions that the telecom industry would make from [traditional SMS text messaging]" she said.
Shares in Facebook dropped 5% in after hours trading before recovering slightly.
Prior to this acquisition, Facebook's biggest buy had been Instagram for $1bn in 2012.
It had also reportedly offered $3bn to acquire photo messaging service Snapchat.