Holed up in a rickety construction trailer on the campus of Stanford University, two graduate students were supposed to be finishing their doctoral studies. Instead, Jerry Yang and David Filo began messing around on the world wide web - at the time, a largely unexplored phenomenon.

Both in their early 20s, Yang and Filo were surrounded by empty pizza boxes, discarded papers and student detritus. They started fiddling with quirky homepages. Yang put up his golf scores, his name in Chinese characters and a list of his favourite websites. As they stumbled on new finds, this index began to grow. It was initially called "Jerry and David's guide to the World Wide Web" but then in 1995 Yahoo was born.

Throughout the rest of the decade, Yahoo was the undisputed leader on internet "portals". When the company went public in 1996, its shares rocketed by 154% in a day and within three years, Yang and Filo were worth $8bn each. Things were going like a dream - until a little known private competitor called Google came along.

"Google came out with a smarter search engine," says Mark Malseed, co-author of The Google Story. "It was much more based on relevance. They made much of their 'purity', their philosophy was that you shouldn't be able to pay to come out higher."

For a time, a tightly fought tussle between Yahoo and Google enthralled Silicon Valley. But Google quickly gained the upper hand, staffing up with cheap talent laid off by larger Silicon Valley firms when the dotcom bubble burst in 2000. By the beginning of this year, Google accounted for three quarters of all searches on the internet. The word Google entered the Oxford English Dictionary.

With a market value of $160bn, Google's power has become awe-inspiring. Its profits rocketed 40% to $4.2bn last year and it swallowed the popular video-sharing website YouTube.

Its success has been greeted with alarm by the corporate establishment. Microsoft, based 800 miles to the north in Seattle, has watched Google diversify into free-of-charge "apps" - applications such as spreadsheets and word processors which encroach on classic Bill Gates territory.

"We've been getting unsolicited feedback this morning from publishers and advertisers that this is the right kind of stuff," said Microsoft's general counsel, Brad Smith, on a conference call with analysts. "This will create a more powerful number two in the marketplace."

The deal, Microsoft's chief executive, Steve Ballmer, suggested, was the only way to make up the gap between Google and the rest of the marketplace: "Sure, we could have hired more engineers. But the market continues to grow and the leader continues to get stronger."

Ballmer, who is Bill Gates's closest lieutenant, is worth $15bn. But in a milestone widely remarked upon in Silicon Valley, his wealth was surpassed last year by Google's founders, Larry Page and Sergey Brin, who each own more than $16bn worth of shares.

Analysts say the bid is a highly unusual move for Microsoft. "This is a very uncharacteristic deal for them," says Michael Gartenberg, an analyst at Jupiter Research. "Ballmer has always had disdain for deals of this size."

It is far from an out-of-the-blue idea. Yahoo's painful struggles have been all too public for years. Although it is still the most visited page on the web, its share of global searches has been steadily shrinking. Microsoft, which holds third place in the search market through its MSN website, tried to talk Yahoo's management into a deal in late 2006 and early 2007, to no avail. Tie-ups between Yahoo and eBay and Disney have been mooted but have come to nothing.

To many, Yahoo's slide has been of its own making. A software update known as Project Panama, which was supposed to tailor advertising to searches far more effectively, suffered a series of catastrophic delays. The company dabbled in social networking, auctions, photo sharing and videos without much conviction or focus. Its blundering efforts to comply with the Chinese government in surrendering the identity of email users prompted a congressman to compare Yahoo to a "moral pygmy". Inside Yahoo, unease became increasingly apparent. In a leaked memo dubbed the "peanut butter manifesto", a senior Yahoo executive, Brad Garlinghouse, complained that the firm was spreading its resources far too thin like a sandwich spread stretched to cover too many slices of bread.

In a bid to restore urgency, Yang retook control of Yahoo last year, ousting its long-serving chief executive Terry Semel. But progress has been slow and Yahoo's shares have trickled downwards.

"Every day the stock does not make progress, every day it continues to wallow, some kind of deal becomes more likely to occur," said Scott Kessler, an analyst at Standard & Poor's after Yahoo revealed a 24% slump in profits earlier this week.

The pressure is on. Yahoo responded non-committally to Microsoft's takeover offer yesterday, saying only that its board would evaluate the bid "carefully and promptly". But shareholders are likely to want to sell.

Together, Microsoft and Yahoo will be able to attract more advertisers to their combined family of websites. It is unlikely they can match Google's acknowledged mastery in "pure" internet searches. For Microsoft, buying Yahoo amounts to an effort to restore its once unshakeable position at the top of the technology tree. But for Yahoo, selling out will be a galling end to once glorious, ground-breaking road.

To reassure unsettled staff, Yang addressed his entire workforce on a hurriedly arranged conference call yesterday. In its proposal, Microsoft suggested it could make $1bn of annual cost savings - a figure which is bound to cause alarm about job cuts.

A tie-up of such magnitude is bound to attract the interest of regulators in the US, and the EU is also likely to investigate. Few, however, believe that the obstacles will be insurmountable.

Bloggers said the battle for online supremacy would be transformed. BusinessWeek's Tech Beat column said: "If it goes through, we suddenly have a two-horse race on the net, with Microsoft-Yahoo the one force with a chance to slow down search giant Google."