ISLAMABAD, Pakistan—A major Pakistani newspaper recently discovered the new limits of press freedom here after it published an interview with ousted Prime Minister Nawaz Sharif in which he questioned the military’s counterterrorism efforts.

Soldiers confiscated copies of the Dawn newspaper in army-controlled regions, officials harassed its distributors, and cable TV networks dropped the group’s TV news station, the company says. The government, then still run Mr. Sharif’s own party, “condemned the fallacious assertions” made by him, after a meeting with top military brass.

Pakistan’s powerful military is stifling the media ahead of a July 25 election, part of a larger power grab that seeks to ensure a pliant government emerges from the polls, say human-rights groups, politicians and media personnel.

“I’ve not seen this before under any democratic rule, not even under martial law,” said Hameed Haroon, Dawn’s CEO and president of the All Pakistan Newspapers Society, which represents newspaper owners. “They seek to influence the election results, influence the national narrative and liquidate the press.”

The military declined to comment. But it has denied accusations of press censorship or political interference, and says it supports democracy.