Needs is an old-fashioned or even archaic adverb in modern English. It comes from the noun need and the Germanic masculine/neuter genitive ending -s, which at some point in time came to be used in older English and other Germanic languages to form adverbs. From the Oxford English Dictionary:
In once, twice, thrice, hence, since, etc., the suffix is written differently. In against, alongst, amongst, amidst, and the dialectal onst (see once), the original -es, -s has become -st.
This suffix is still frequent and semi-productive with other stems in Dutch: onverwachts "unexpectedly", daags na "a day after", etc. I believe German has similar examples. English always, sideways etc. contain the same suffix.
In Old English or earlier, before the emergence of the adverbial suffix -s, there existed several masculine and neuter words in the genitive case—which ended on -(e)s—that were used adverbially: dæges "by day", nédes "needs", þances "voluntarily". By analogy, this masculine/neuter genitive ending was extended to make adverbs out of feminine nouns as well, as in nihtes "by night". From there it became a general adverbial suffix. (Examples were taken from the OED.)