In a legal blow to the National Rifle Association, a New York state judge ruled that the gun-rights group can’t stop its former ad agency from cooperating with a state regulatory probe into the NRA’s financial dealings with its own top officials.

The ruling Monday came in response to a lawsuit filed in September by New York Attorney General Letitia James, whose office has been investigating the NRA’s compliance with rules governing nonprofits.

...