The National Rifle Association has formed an unlikely alliance with the liberal American Civil Liberties Union in support of a court action over the NSA's collection of phone data of millions of Americans.

The ACLU is challenging the constitutionality of the intelligence agency's action, which was revealed in a top-secret document obtained by the whistleblower Ed Snowden and published in the Guardian in June.

The NRA, in an amicus brief in support of the ACLU, argues that the mass surveillance programme provides "the government not only with the means of identifying members and others who communicate with the NRA and other advocacy groups, but also with the means of identifying gun owners without their knowledge or consent".

The NRA hinted at its opposition to the phone data collection soon after the Guardian report and has now formalised it. The organisation is regularly criticised by the left as rightwing and berated for its unswerving opposition to reform of gun laws. But it carries a lot of weight with Congress, claiming five million members and being extremely well funded.

The ACLU case is scheduled to be heard in a New York court but is likely to move up to higher courts, perhaps even the supreme court.

Also filing an amicus brief in support for the ACLU on Wednesday was the Reporters Committee for Freedom of the Press. It argues the collection of data will seriously undermine the ability of journalists to protect sources. "The integrity of a confidential reporter-source relationship is critical to producing good journalism, and mass telephone call tracking compromises that relationship to the detriment of the public interest," it says.

"Wholesale government monitoring of telephone users leaves them uncertain of the privacy of their communications and thus unwilling to exchange information or participate in meaningful conversations. Amici are concerned that, if left unchecked, the mass call tracking at issue here will infringe on the newsgathering rights of journalists and harm the public interest in journalism of all types."

The ACLU, welcoming the support of the NRA and others, said: "The range of voices joining the protest against mass government surveillance – not to mention the bipartisan storm since the recent NSA disclosures – is a real testament to the fact that the government's dragnet surveillance practices are offensive to Americans from across the political spectrum."

The ACLU case challenges the government's ongoing collection under section 215 of the Patriot Act.