SEOUL, South Korea — Stung by the outbreak of Middle East respiratory syndrome, South Korea has passed a law authorizing prison terms of up to two years for people who defy quarantine orders or lie about their possible exposure to an infectious disease.

South Korea has had 181 confirmed cases of the disease known as MERS, including 31 deaths. The outbreak, which began last month, is the worst seen outside Saudi Arabia, where the disease was first identified.

The spread of MERS here has been attributed mainly to poor infection control at the country’s hospitals, as well as failures of communication and coordination on the government’s part. But the public has also been angered by reports of people flouting orders to stay home while they were being monitored for symptoms. One such person went golfing; another went to China, where he was detained and later tested positive for MERS. Under current law, such defiance can result in a fine but not imprisonment.

The new law, which was passed on Thursday and takes effect in six months, gives more authority to public health investigators, empowering them to close down the site of a possible outbreak of infectious disease and to place people there under quarantine. People who defy the orders can be sentenced to up to two years in prison or fined up to 20 million won, or about $18,000. The same penalties can be imposed for lying about one’s possible exposure to infectious disease.