Caveat: This is a forum post, not a researched thesis, so take with a grain of salt. It's similar to what Hussar has said, but expands on it in a few ways.
Trying to think of differentiators...
Sci-fi:
Ghost in the Shell
Battle Angel Alita
2001
I, Robot
Foundation series
Each of them contains multiple stories within them. Murder mysteries, political thrillers, war, rebellion, sports, etc, but those descriptors wouldn't be considered those series' "genre". They are all indisputably sci-fi. They also all contain impossible, "non-scientific" elements. The "fantastical" elements do not make these part of the fantasy genre.
They all, however, deal with issues of identity, particularly in contrast with changing culture. Either the world changing around the protagonist, or the protagonist changing beyond the pace of the world. What does it mean to be human? What is moral and/or ethical?
The more I think through sci-fi stories I can bring to mind, the more common this one trait is: It asks a question that touches on ethics, morality, choice, or identity, and tries to explore how that question can be answered.
Fantasy, on the other hand, does not. It never tries to question the self; rather, it tries to manifest the inner self. Farm boy to hero. Believe in yourself. Destiny. Morality is simple; it's assumed to be true. You're the hero, and must defeat the enemy. It's a matter of holding onto your morals, and avoiding being corrupted (eg: Lord of the Rings).
Sci-fi questions morals, while Fantasy reinforces morals. Sci-fi questions identity, while Fantasy shapes identity. Sci-fi pokes and prods and tries to answer questions, while Fantasy takes those answers as a given, and tries to show you that they're good.
Hard sci-fi takes science seriously, and asks serious questions about its implications. It's primarily interested in the impact of technology on the questions it asks. Soft sci-fi divorces the questions from real science so that it can ask questions that don't easily fit within scientific boundaries. It's primarily interested on the impact of people on the questions it asks.
Fantasy shapes a story to build a moral lesson (such as the classic Grimms' Fairy Tales), or show the goodness of following a moral path (eg: stand against corruption, defeat evil).
So Star Trek would be soft sci-fi, while Star Wars would be Fantasy.
If magic is in sci-fi, it must necessarily be soft sci-fi, because there's no point in rigorously examining an unreal rule system. In fantasy, however, magic is merely a tool, and is included more for entertainment's sake than because it's a requirement of the genre. You could just as easily have a science-based setting, leading to "Science Fantasy".
Sci-fi almost always has futuristic settings because the questions it asks are inevitably, "What are the implications of this change?" That question is forward-looking; it's implicitly about the future, and thus carries with it everything we have in the present, plus a little. Fantasy is period-agnostic, but it's often easier to tell the story in a simpler environment, such as a pseudo-medieval setting, where modern technology doesn't undermine or second-guess everything you do.
So those are my further thoughts on the distinction between sci-fi and fantasy.