Although we tend to conflate the two terms in everyday use, there is definitely a difference between sex and gender. Sex is biological. Gender is cultural.
Sex is a biological fact. While there are some intermediate cases, essentially every person in the world is biologically male or female. This has to do with things like genitalia, internal sex organs, hormones, and the like. There is, for the most part, no dispute about whether a person is male or female. That person would be identified in the same way (as either male or female) in any culture.
By contrast, gender is a cultural construct. Gender is the set of behaviors and attitudes that we are expected to display because of our sex. This set of behaviors and attitudes can differ across cultures. They are connected to sex, but they are not the same thing as sex. For example, in one culture, it may be considered manly to do work on a farm while in another culture only women work on farms and men would be humiliated if they had to do so. This is a difference in the way gender is constructed in those societies.
Thus, these are different things because sex is a biological fact and gender is a cultural construct.