Google reached an agreement today to acquire DoubleClick, the online advertising company, from two private equity firms for $3.1 billion in cash, the companies announced, an amount that was almost double the $1.65 billion in stock that Google paid for YouTube late last year.

The sale offers Google access to DoubleClick’s advertisement software and, more importantly, its relationships with Web publishers, advertisers and advertising agencies.

For months, Google has been trying to expand its foothold in online advertising into display ads, the area where DoubleClick is strongest. Google made its name and still generates most of its revenue from search and contextual text ads.

DoubleClick, which was founded in 1996, provides display ads on Web sites like MySpace, The Wall Street Journal and America Online as well as software to help those sites maximize ad revenue. The company also helps ad buyers — advertisers and ad agencies — manage and measure the effectiveness of their rich media, search and other online ads.