A North Carolina law requiring women to undergo an ultrasound four hours before an abortion has been declared unconstitutional by a federal court.

The fourth circuit court of appeals on Monday found that the so-called “women’s right to know” law was “compelled speech” and in violation of the first amendment.

The law contains a “real-time view requirement”, which compels doctors or ultrasound technicians to perform an ultrasound on any woman seeking an abortion, display the sonogram to her, and describe the foetus in detail.

It also obligated doctors to offer to let the woman hear the foetal heartbeat.

“The requirement is quintessential compelled speech,” wrote J Harvie Wilkinson, one of the circuit court judges, in the 37-page legal opinion. “It forces physicians to say things they otherwise would not say. Moreover, the statement compelled here is ideological; it conveys a particular opinion.”

The law came into effect in 2011, but was immediately challenged in the federal district court. Judge Catherine Eagles at the time ordered the real-time view requirement part of the law be placed under injunction until its constitutionality could be established.

“We’re thrilled that the appellate court rejected this unconscionable attempt to intrude on the doctor-patient relationship,” said Nancy Northup, president and CEO of the Center for Reproductive Rights, in a press release.

“Exam rooms are no place for propaganda and doctors should never be forced to serve as mouthpieces for politicians who wish to shame and demean women.”