The firms, which ran sports betting, gambling and casino ads online, have said they have since stopped hosting such ads, which are banned under US law, on their Stateside operations.
Microsoft is expected to pay out a total of $21m in fines and has agreed to make a third of the sum a charitable donation to causes helping exploited children. The company will also fund a $9m three-year ad campaign highlighting the dangers of online gaming.
Yahoo! has been fined $3m, and will also donate $4.5m to an ad campaign warning that people who take part in online sports gaming in the US are liable to arrest and prosecution. Google will also pay out $3m to the US authorities.
In a statement, Microsoft said it had ceased accepting online gaming ads four years ago, while Yahoo! said it had not done so "for years". Google said it voluntarily stopped running internet gaming ads in April 2004.
Meanwhile, Viacom has signed a five-year $500m ad and content distribution deal with Microsoft that ends the media group's ties with DoubleClick, the ad serving company currently subject to a regulatory investigation for a proposed acquisition by Google.
Under the agreement, Viacom will be able to screen online ads for its TV output, which includes shows on MTV, Comedy Central and Nickelodeon, on Microsoft's MSN site and Xbox 360 games system.
The deal also means Microsoft also has exclusive rights to find buyers for unsold display ad space across Viacom's sites in the US.