WASHINGTON—The National Security Agency violated the Constitution for three years by collecting tens of thousands of purely domestic communications without sufficient privacy protection, according to a secret national-security court ruling.

In the strongly worded 2011 ruling, released Wednesday by the Obama administration, the court criticized the NSA for misrepresenting its practices to the court. It noted that the illegal collection was the third instance in less than three years in which the government made a "substantial...