c.1400, "foul, filthy, dirty, unclean," of unknown origin; perhaps [Barnhart] from Old French nastre "miserly, envious, malicious, spiteful," shortened form of villenastre "infamous, bad," from vilein "villain" + -astre, pejorative suffix, from Latin -aster.
Alternative etymology [OED] is from Dutch nestig "dirty," literally "like a bird's nest." Likely reinforced in either case by a Scandinavian source (cf. Swedish dialectal naskug "dirty, nasty"), which also might be the source of the Middle English word. Of weather, from 1630s; of things generally, "unpleasant, offensive," from 1705. Of people, "ill-tempered," from 1825. Noun meaning "something nasty" is from 1935. Related: Nastily; nastiness.