The deal will hand BT the UK's most advanced 4G network, as well as an extra 31 million customers.
BT will pay a mix of cash and shares to EE's owners, Deutsche Telekom and Orange. It will raise £1bn through selling shares to help finance the deal, as well as using debt.
Deutsche Telekom will take a 12% stake of the combined business and Orange will hold 4%. The trio have been in talks since December.
The deal will instantly make BT the biggest telecoms firm in the UK, in what Gavin Patterson, the chief executive officer, describes as a "major milestone" for the company.
He said: "The company exited the mainstream mobile market in 2001 when it spun off O2, which would later become part of Spanish operator Telefonica.
"[The deal] will allow us to accelerate our mobility plans and increase our investment in them. The UK’s leading 4G network will now dovetail with the UK’s biggest fibre network, helping to create the leading converged communications provider in the UK."
Olaf Swantree, EE's chief executive, said the deal would keep the UK at the "forefront" of mobile.
He said: "In the last few years alone, we have built the UK’s biggest, fastest and best 4G network, significantly advancing the digital communications infrastructure for people and businesses across Britain.
"Today’s announcement will ensure the UK remains at the forefront of the mobile revolution, bringing even more innovation and investment in world leading connectivity for our customers."
It isn't clear what will happen to EE as a brand, though its relative nascence means it will likely be subsumed into BT.
BT isn't commenting on potential job losses either, though Patterson said the merger would mean "significant opportunities" for employees.
The deal will still face practical regulatory hurdles, with BT hoping to achieve £3bn in cost savings.