It all depends on believable and well-drawn characters, strength of storylines, and consistently good writing. Now, with programmes such as Breaking Bad, The Wire, The Sopranos, etc they had a very strong, straightforward, and clear central plotline from which they rarely deviated - and they knew when it was time to call it a day, and how to do so in a satisfying and logical way. It was easier to do in these cases as they were based on real life - ordinary (ish) people in a non-mundane but not-paranormal context. Battlestar Galactica, Star Trek and Dr Who (discuss) do have a non-normal theme, but again all stick to a driving, clear narrative. The premise was non-terrestrial, but the narrative was human and believable. Unexpected stuff happens in all the above, but in a realistic way, as it happens to us all to a greater or lesser extent.
The problem the X-Files, Heroes, etc had is that they a) all went on too long, b) had to keep trying to better what they did last week, or last season (so start chucking in more and more outlandish stuff), and c) all at some point start pissing around with labyrinthine conspiracies and /or time travel - at which point 99% disappear up their own arses.
That's my theory anyway.