"This commercial agreement provides Yahoo with the opportunity to deliver more relevant ads to users and provide advertisers and publishers with better advertising technology," said Eric Schmidt, Google chairman and chief executive.
"We believe that the convergence of search and display is the next major development" in online advertising industry, said Yahoo chief executive Jerry Yang.
The partnership will initially last for three years, but could last up to 10 if Yahoo decides to renew.
Google said the deal did not need regulatory approval but that it would delay its implementation by up to three and a half months to give the US Department of Justice a chance to review it.
However, the deal is likely to attract attention from competition regulators in Washington, according to the BBC's technology correspondent Rory Cellan-Jones.
"Alarm bells were already ringing on Capitol Hill over Yahoo's 'limited' trial in April of Google's technology," he said.
The markets closed before the Google deal was announced. Shares in Yahoo had closed down 10% after it said its attempts to revive Microsoft's $47.5bn (£24bn) offer for the whole of Yahoo had been unsuccessful.
Yahoo chiefs strike deal
The shares fell as low as $22.50 earlier in the trading session, their lowest level since the software giant first offered $31 a share for Yahoo in January.
Yahoo rejected a new proposal from Microsoft to buy just its online search operations.
“In the weeks since Microsoft withdrew its offer to acquire Yahoo, the two companies have continued to discuss an alternative transaction that Microsoft believes would have delivered in excess of $33 per share to the Yahoo shareholders," Microsoft said in a statement.
"This partnership would ensure healthy competition in the marketplace, providing greater choice and innovation for advertisers, publishers and consumers," the company said.
Yahoo, however, did not want to sell off only one part of the business.
It said such a deal "would not be consistent with the company's view of the converging search and display marketplaces".
Microsoft sources told the BBC's Rory Cellan-Jones that the company was no longer interested in a full takeover because Yahoo had been "underperforming" and was losing some of its key staff.
Yahoo's shares closed 10% lower at $23.52, while Microsoft finished 4.1% higher at $28.24.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.