Plan B pill

How exactly does it work? If I had sex and a guy came inside me is it supposed to technically stop pregnancy if I take it right after sex?