If your application for a residence permit has been rejected, this means that you do not have the right to stay in Sweden. If the Swedish Migration Agency rejects your application while you are in Sweden, you will have a certain amount of time to leave the territories of the Member States and the Schengen area. The decision states the deadline by which you must leave. If you remain here after that date, you will be in the country illegally.
It is your responsibility to make sure you know what applies to you, so that you leave Sweden within the deadline stated in the decision.
If you have appealed the decision, in some cases you can stay in Sweden while you wait for the court’s decision. The decision states whether or not you have the right to stay in the country while your appeal is being examined.
Once the decision has come into force and can no longer be appealed, you must leave the territories of the Member States and the Schengen area.
If you have received a refusal of entry decision that must be implemented immediately
If you have received a refusal of entry decision that is to be implemented immediately, you must leave Sweden as soon as you have received the decision, even if you choose to appeal.