The ad, called "New Energy," accuses McCain of being "part of the problem" of high gas prices and shows archived footage of the Arizona senator embracing President Bush. The narrator says Obama "will make energy independence an urgent priority."
The Obama campaign said that the contrast ad was a response to "false, negative ads" launched by the Republican National Committee.
"New Energy" will run in the battleground states of Michigan, Ohio, Pennsylvania and Wisconsin.
Watch the ad below.