The morning after pill is also known as emergency contraception. It is like a super strong dose of the birth control pill.
It works best if taken within 24 hours of unprotected sex, but can help reduce the chances of pregnancy up to three days afterwards.
The laws regarding this vary - if you're in the UK I can advise you, but if you are in another country you will be able to get this information from sexual health services like Planned Parenthood (for the USA), etc.