CNN got a nice October surprise from Nielsen as it finished first in the key demographic of 25- to 54-year-olds in both prime time and total day among cable news networks, the first time in 15 years it accomplished that feat.

All the cable channels have seen ratings surge as a result of election coverage.

While Fox News won the total viewership title among news outlets, CNN took the 25-54 demographic that advertisers covet. In prime time, CNN averaged 710,000 viewers in that category, up 131% from last October, according to data from Nielsen. Fox News was second with 671,000 viewers, an increase of 124% from last year. MSNBC jumped 224% to 438,000 viewers in that age category.

In total viewers, Fox News continues to dominate, but CNN and MSNBC have made significant gains.

Fox News parent 21st Century Fox and Wall Street Journal-owner News Corp share common ownership. CNN is owned by Time Warner Inc., which has agreed to be acquired by AT&T for $85.4 billion.

For prime time, Fox News finished first with an average audience of almost 3.1 million for October, a 72% jump from last year and more than all the other cable news and entertainment channels. CNN nearly doubled its prime-time audience to 1.9 million, trailing only Fox News and ESPN.

MSNBC more than doubled its average prime-time audience with 1.7 million viewers and finished sixth among all cable channels.

For CNN, this was the fourth time this year it beat Fox in viewers aged 25-54. It also won in total day in that category for the first time in seven years. CNN hasn’t finished in first in both categories for a month since 2001, a month after the Sept. 11 terrorist attacks.

On weekdays, Fox News won in the 25-54 category by 5,000 people on average, thanks to Bill O’Reilly, Sean Hannity and Megyn Kelly. However, on weekends in prime time, CNN’s margin of victory was wide enough to give it the title for the month.

The news channels aren’t the only ones getting a boost out of the election. In October, Fox Business Network, sister network to Fox News, scored its first win over rival CNBC in total viewers during the day—which is the equivalent of prime time for business news channels.

For the month, Fox Business Network averaged 170,000 viewers, up 67% from the same month a year ago while CNBC averaged 164,000 viewers, according to Nielsen. Fox Business Network has focused much of its coverage on the election and implications for the economy.

CNBC did win among adults aged 25-54. The financial news network has long argued that Nielsen ratings don't fully capture its audience and last year stopped using the service to measure its daytime audience.

The question for all the cable networks is what will happen to their audiences on Nov. 9. If history is a guide, all the news networks will see significant declines once the shouting is over and the dust settles after the election.

Write to Joe Flint at joe.flint@wsj.com