While Donald Trump's election victory was credited for fueling a broad bump in stock prices, few sectors benefited as much as media did.

The S&P 500 media index gained 9.4% in the first quarter, led by high-profile Viacom (VIAB) - Get Report (32.8%), 21st Century Fox (FOXA) - Get Report (15.5%) and Disney (DIS) - Get Report (8.8%). That compared favorably with the S&P 500 index, the benchmark market that was up a healthy 5.5%. Other stocks to outshine the broad market included Tegna (TGNA) - Get Report (19.8%), Charter Communications (CHTR) - Get Report (13.7%), News Corp. (NWSA) - Get Report (13.4%) and CBS (CBS) - Get Report (9%).

The generally upbeat performance by publicly traded media companies in the first quarter comes as national television advertising revenue continues to decline amid a nearly five-year drop in subscribers to pay-TV services. Heightening the challenges for media conglomerates, movie theater attendance also fell in 2016, an ominous sign for companies that own Hollywood studios.

But in the wake of a spirited presidential campaign topped off by Trump's surprising victory, media stocks have begun 2017 with a bang.

A handful of stocks -- Gray Television (GTN) - Get Report (33.2%), Sinclair Broadcasting (SBGI) - Get Report (21.4%), Tribune Media (TRCO) - Get Report (6.5%) and Tegna among them -- have been bolstered by expectations that the FCC under Republican-appointee Ajit Pai will relax rules aimed at curbing media concentration. With fewer regulations designed to limit consolidation, Sinclair, among others, has made clear that it intends to acquire more television stations to better compete for national advertising. 

A potential turnaround story, Viacom was the top performer among stocks in the S&P 500 media index, surging as new CEO Bob Bakish continues to take bold steps to try to restore prominence to the once-mighty owner of Paramount Pictures and the Nickelodeon cable TV network. Viacom's first-quarter jump came after a two-year period in which shares lost 53% as former CEO Philippe Dauman focused much of his attention on an ultimately losing campaign to wrest control of the company from its longtime majority owner, Sumner Redstone, and his daughter, Shari.

Disney climbed in the quarter as CEO Bob Iger said he would remain atop the world's largest media company through June 2019. Iger's decision to accept a $5 million bonus to extend his contract helped to ease investor concerns that its largest profit center, ESPN, continues to lose subscribers. Iger has vowed to lower costs at the sports titan while expanding its reach through a rising number of new digital standalone platforms.

Fox rebounded in the first quarter as its fiscal second-quarter earnings beat expectations on a surge in political ad spending and high ratings for sports events including the World Series won by the Chicago Cubs. Sports remains the most valuable property of broadcast TV owners. CBS, despite a drop in ratings for the NFL, also gained 9% in the quarter after gaining 36% in 2016.

Shares of News Corp., owner of The Wall Street Journal, as well as New York Times Co. (NYT) - Get Report (8.1%), posted strong gains in the quarter fueled by a growth in digital subscriptions

Despite the heady gains of the quarter, however, media companies face multiple challenges, most notably those that own cable TV channels. Fourth-quarter national cable advertising sales showed no growth compared with the same period a year earlier despite a surge in revenue for cable news networks, according to data compiled by Goldman Sachs.

Ratings also are under pressure as audiences continue to fragment, pulled this way and that by Netflix (NFLX) - Get Report , Facebook (FB) - Get Report and Snap (SNAP) - Get Report , among many other video diversions not tied to the traditional cable TV bundle. Of the top 25 shows on broadcast television, only two have posted a ratings increase during the fall-winter season, according to Nielsen. The average rating for the top 79 scripted shows on broadcast TV among viewers aged 18 to 49 was 13% lower than for the 2015-16 TV season. 

Facebook is a holding in Jim Cramer'sAction Alerts PLUS Charitable Trust Portfolio. Want to be alerted before Cramer and the AAP team buy or sell FB? Learn more now.