It looks like it is originated as a slang term for drugs, then gained a broader usage in time. Below is an excerpt from The Routledge Dictionary of Modern American Slang and Unconventional English edited by Tom Dalzell:
And here is the earliest usage of the shit as a drug in 1967 from the book How to Talk Dirty and Influence People By Lenny Bruce:
(the earliest usage I could find)
There is an Urbandictionary entry related:
The best. Originated as a term to describe high quality drug substances. IE, "this is good shit."
Evolved to common usage for any item of high quality. However, in typical usage, the article "the" is required to denote superiority. Without the word "the" prefacing the word "shit," a different, usually negative, meaning applies.
There is also the shiznit but even shiznit is used instead of the shit.
shiznit: More "urbanized" form of the shit. Basically means really, really good. Other versions include:hella cool,tight, the best. [Urbandictionary]
1.something really cool.2.used to express joy in something/someone.3.to express that something is really or very good. [Urbandictionary]
There is also a less common term, the junk.
The epitomy of being sick, dope, or tight. [Urbandictionary]
Note: One needs to be careful though, because the shits means diarrhea.