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 - still, 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 list of his favourite websites. As they stumbled on new finds, this index began to grow. It was initially called "Jerry'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 (£4bn) 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, set up in a Menlo Park garage, quickly gained the upper hand, staffing up with cheap talent laid off by larger Silicon Valley firms when the dotcom bubble burst in 2000.

"A lot of firms, including Yahoo, were letting people go," says Malseed. "Meanwhile, Google was growing - and growing cheaply. They were able to hire good people at great rates."

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. It became Hertz, to Yahoo's Avis.

"It was really about Google's execution - in terms of technology, in terms of strategy," says Michael Gartenberg, an analyst at Jupiter Research. "Google was the upstart - but it executed so quickly and so successfully that it left the other companies behind."

With a market value of $160bn, Google's power has become awe-inspiring. It 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.

Once a byword for monopolistic behaviour itself, Microsoft has frequently cried foul. Its general counsel went to the US Senate last year to try to stop Google from buying an advertising firm, DoubleClick.

Google, said Microsoft's general counsel Brad Smith, was already like FedEx and several other firms combined.

"Now they're proposing to buy the post office," he said.

Through Microsoft's $44.6bn takeover bid for Yahoo, the technology establishment hit back at Google's seemingly unstoppable rise.

On a conference call with analysts, Microsoft's chief executive, Steve Ballmer, made no bones about the intention.

"We've been getting unsolicited feedback this morning from publishers and advertisers that this is the right kind of stuff," said Ballmer. "This will create a more powerful number two in the marketplace."

The deal, he 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' closest lieutenant, is worth a cool $15bn. But in a milestone widely remarked upon in Silicon Valley, his wealth was surpassed last year by Google's founders, Larry Page and Sergei Brin, who each own more than $16bn worth of shares.

Analysts say the bid is a highly unusual move for Microsoft - and is a sign of its anxiety to get back in the internet game. It is the biggest takeover offer in the US since AT&T merged with Bell South in early 2006.

"This is a very uncharacteristic deal for them," says Gartenberg. "Ballmer has always had disdain for deals of this size."

Most visited page on the web

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 both 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.

"We focus on nothing in particular," he observed in a devastating critique of his own superiors. "We lack a focused, cohesive vision for our own company ... we lack decisiveness."

In a bid to restore urgency, Yang re-took control of Yahoo last year, outsting its long-serving chief executive Terry Semel. Some fancy new Yahoo devices for mobile phones went on display at the Consumer Electronics Show in Las Vegas this month. But still, 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.

At the time, another Wall Street expert complained: "Basically what Yahoo is saying is 'have more patience with us' when investors have already given them two-and-a-half years to transform their business."

The pressure is on. Yahoo responded non-commitally to Microsoft's takeover offer today, saying only that its board would evaluate the bid "carefully and promptly".

But shareholders are likely to want to sell the company. Youssef Squali, a technology expert at stockbroker Jeffries & Co, said: "Yahoo and Microsoft are a natural combination. The board [of Yahoo] is going to have a hard time resisting the deal."

Together, Microsoft and Yahoo will be able to attract more advertisers to their combined family of websites. It is unlikely that they can match Google's acknowledged mastery in "pure" internet searches. But with the onset of so-called "Web 2.0", cyberspace is expanding in a social direction through networking websites, collaborative dictionaries, music and video sharing. Microsoft's recent purchase of a stake in Facebook made its ambitions clear - and Google has been noticeably weak on this front.

"Google just hasn't had any traction with its own social networking attempts," says Malseed.

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.

Yang likes to style himself under the job title "chief Yahoo". The company's advertising used to feature a distinctive yodel which prompted a $5m copyright lawsuit from a "professional yodeller" in Washington state who claimed to have written the ditty. It is unlikely that such quirks will survive within the multinational corporate embrace of Microsoft.