Spain's government has approved legislation restoring universal free health care to all residents, thus reversing a previous law passed by its conservative predecessor that had excluded some sections of society, officials said Friday.

The cabinet approved the new law at its end-of-week meeting in Madrid, saying the change would make it easier to control diseases and should also avoid imbalances that tend to provoke a need for emergency treatment and hospitalization.

"Today, Spain recovered its right to universal health care," the ministry of health said. "The cabinet has approved the proposal by Health Minister Carmen Montón and given the green light to a law that will guarantee universal health care to all persons with Spanish nationality as well as foreigners resident in Spain," the ministry added.

Spain's health care system ranks among the best in the world and is funded by social security payments, meaning the vast majority of the population does not require private insurance for medical treatment.

The cabinet of Socialist Prime Minister Pedro Sánchez thus reversed a law passed by the conservative Popular Party which under then PM Mariano Rajoy had withdrawn health cover from immigrants in an irregular situation, said Isabel Celaá, the government's spokeswoman and education minister.

According to Celaá, the legislation fulfills one of the main commitments of her government.

Now, immigrants in an irregular situation will have the right to health care under the same conditions as Spaniards without having to justify their residence in Spain if social services confirm that their country of origin cannot pay toward the cover.