Most shows fall into that category. It's hard to sustain outstanding quality beyond 5 years. And even if the writing remains up to par people tire of watching the same shows as new competition comes along in addition to changes that occur in one's personal life and schedule. Introducing new characters and losing old characters over the years also changes a show's makeup and storyline.
"ER" and "Greys Anatomy" started off hot but after every doctor has slept with every other doctor and every medical emergency surgery you could imagine takes place things get old fast. Right now "Scandal" is the hot talked about show and it's getting near the point of having too may plot twists for it's own good. "Lost" ran out of steam and it's finale disappointed many of it's fans. However the "Sopranos" really let their fans down.
Sitcoms based around a family of children have it difficult as the children become older and less cute in their looks and actions. This killed "The Cosby Show" in my opinion. "Sex And The City" wore out every conceivable dating/relationship scenario a woman could have without getting married. Near the end of it's run they looked liked 4 bitter old used up women blaming men for their unhappiness none the wiser for all the experiences they had.
Other shows lose their edge when they eventually couple two leading actors together after seasons of having sexual tension. This happened with "Moonlighting" and most recently with "Castle". Once they hookup there is nowhere else to go. Instead of the audience hoping one day they'll be together as they tune in each week they end up finally getting together and it's "not the end". Therefore the writers have to contrive disagreements and misunderstandings or breakups to fill out the rest of show's run. They should save the pairings for the show's final season.
The shows with the best runs in my opinion are usually those without children in them. "Jerry Seinfeld" went out on top. I also thought that "Cheers" had a great run as well.