Yahoo will be combined with AOL, another faded internet star, which Verizon bought last year.
The deal does not include Yahoo’s valuable stake in Chinese firm Alibaba.
The price tag for the deal is well below the $44bn Microsoft offered for Yahoo in 2008 or the $125bn it was worth during the dot.com boom.
Verizon said the deal for Yahoo’s core internet business, which has more than a billion active users a month, would make it a global mobile media company.
The end of Yahoo: Why Verizon spent big
1994 Yahoo – which stands for Yet Another Hierarchically Organized Oracle – is founded
2000 Yahoo valued at $125bn at height of dot.com boom
2002 Google rejects a $3bn bid from Yahoo
2008 Microsoft’s $44.6bn offer for Yahoo is turned down
2013 Blogging site Tumblr acquired by Yahoo for $1.1bn
2015 Yahoo makes net loss of $4.4bn
2016 Verizon agrees $4.8bn deal to buy Yahoo
Marissa Mayer joined Yahoo four years ago
Marissa Mayer, chief executive of Yahoo, said: “Yahoo is a company that has changed the world, and will continue to do so through this combination with Verizon and AOL.”
In an email to staff, Ms Mayer said she was “planning to stay”, adding: “I love Yahoo, and I believe in all of you. It’s important to me to see Yahoo into its next chapter.”
However, the takeover, which is due to be completed in early 2017, raises questions about whether the Yahoo brand could disappear.
“That’s the big open-ended question: what are they going to do with the brands?” said Michael Goodman, a director at Strategy Analytics.
Yahoo’s websites include photo sharing service Flickr
Analysis: New York business correspondent Michelle Fleury
While this is a sad day for Yahoo – as big as Facebook and Google in its prime – it raises interesting questions about its new owner. What are Verizon’s ambitions?
Beyond the talk of becoming a global media company, Verizon chief executive Lowell McAdams wants a larger share of the booming digital advertising pie. And he thinks this deal will help him.
As a leading US mobile phone network, Verizon already had a wealth of data from smartphone users that it could mine.
Its purchase of AOL a year ago for its programmatic advertising technology allowed it to leverage that more effectively. Yahoo, meanwhile, has struggled to build its mobile advertising business. Its appeal is that it has content.
With Yahoo, Verizon gains the internet company’s 600 million monthly active mobile users, as well as its email service, Yahoo Finance, and Tumblr, which is popular among millennials.
So is Verizon ready to take on the likes of Google and Facebook? In 2015, these two tech behemoths claimed the largest share of the digital ad market. Whether or not Verizon can challenge that remains to be seen – but that’s certainly the idea.
AOL chief executive Tim Armstrong said the deal was about “unleashing Yahoo’s full potential”, and creating a major player in mobile media.
Together AOL and Yahoo will have more than 25 brands, including Yahoo Mail, Flickr and Tumblr as well as AOL’s Huffington Post and Techcrunch news sites.
Ms Mayer, who took the helm at Yahoo in 2012, has made little progress in returning the company to profit.
Last week the firm reported a $440m loss in the second quarter, but said the board had made “great progress on strategic alternatives”.