TEHRAN—Iran is temporarily releasing tens of thousands of prisoners in an attempt to prevent the spread of the coronavirus in the country’s crowded prisons, as it struggles to contain one of the worst outbreaks of a disease that has already killed dozens of people and infected 23 lawmakers.

More than 54,000 prisoners have gone out on furlough after testing negative for the virus, judiciary spokesman Gholamhossein Esmaili said Tuesday. He indicated that several prominent Iranian political prisoners and British dual national...