Sex is biological and social.
Gender is about grammar and pronouns. It is a lot more important in other languages than English, and often has nothing to do with sex. There are languages where the genders are "alive" and "dead", or "adult" and "child or animal".