The new law reintroduces the good behaviour requirement which existed in Swedish migration law prior to 2005, referred to in Swedish as the vandelskrav.
This means that foreigners considered to have so-called bristande vandel, roughly a flawed way of life or poor conduct, will no longer qualify for a residency permit.
"If you for example neglect to pay your debts, if you don't follow decisions by Swedish authorities, if you cheat on benefits or if you cheat in order to get a Swedish residence permit – well, then you don't have the right to be here," Migration Minister Johan Forssell told a press conference when he introduced the bill earlier this spring.
Other factors that could be considered as poor conduct could be working illegally or not paying fines. Prostitution, begging and substance abuse as such are not included.
Statements should not in and of themselves count as poor conduct, but could be used to confirm a permit holder's links to violent or extremist organisations.
The new law will apply retroactively. This means that all residence permits will be affected, not just those issued after it comes into force.
Previous poor conduct will also be grounds for revocation, but not on its own, only together with actions that take place after the law comes into force.
The new rules will apply to everyone whose residence permit is based on Swedish immigration law, such as work permits and family members.
They will not apply to foreigners whose right to stay in Sweden is based on EU law and conventions, such as refugees, EU citizens and third country citizens in Sweden on an EU permit.
Critics of the new law have argued that the poor conduct requirement is too open to interpretation and risks undermining the rule of law in Sweden.
The largest centre-left opposition party, the Social Democrats, said they were opposed to the law, but framed their counter-motion as a non-binding tillkännagivande, not a motion to reject.
Parliament in the end voted in favour of the law on June 16th. The new rules are set to come into force on July 13th.