Good question, as these two genres are very similar. I'll define each and then give what the main difference is.
Science fiction: fiction based on future/alternative scientific or technological advances with imagined but plausible events such as alternate universes, robots taking over the world, space travel, etc.
Fantasy: fiction characterized by magic and/or other supernatural phenomena as a primary element.
While these two genres do obviously overlap, the main difference seems to be that science fiction deals rationally with events that are plausible under the story's own stated laws of nature. More simply, in a science fiction novel, there is reason given behind how/why things happen, and in fantasy things happen just because they happen.
For instance, Doctor Who is a good example of science fiction. Even though seemingly supernatural things happen in his adventures, there is always an explanation based on the laws of nature within the show. Harry Potter, on the other hand, is fantasy because the magic they do isn't given an explanation based on nature, only that their wands can help them to produce magic.
Hope this helps!
I've taught a course in science fiction.