They're usually the same thing, differing only thematically. Some "hard" sci-fi may be completely grounded in reality, but for most the "sci" is just a background setting. Many space operas are even more fantastical than wizards throwing fireballs at each other. Some fantasy writers go far out of their way to build coherent worlds governed by physical laws just as strict as our own. Both/Either/The genre(s) use the flexibility of an imagined world, whether that's an imagined future or some land of myth, to contrast with the present, and as with the fantastical myths of old, to make moral or political points that couldn't be so easily expressed if weighed down by history and nuance.