early 14c., "row, line series;" c. 1400, a row of an army, from Old French renc, ranc "row, line" (Modern French rang), from Frankish *hring or some other Germanic source (compare Old High German hring "circle, ring"), from Proto-Germanic *hringaz "circle, ring, something curved," from nasalized form of PIE root *sker- (2) "to turn, bend."
Meaning "a social division, class of persons" is from early 15c. Meaning "high station in society" is from early 15c. Meaning "a relative position" is from c. 1600.
Sense evolved in Middle English to "large and coarse" (c. 1300), then, via notion of "excessive and unpleasant," to "corrupt, loathsome, foul" (mid-14c.), perhaps from influence of Middle French rance "rancid." In 17c. also "lewd, lustful."
Much used 16c. as a pejorative intensive (as in rank folly). This is possibly the source of the verb meaning "to reveal another's guilt" (1929, underworld slang), and that of "to harass, abuse," 1934, African-American vernacular, though this also may be from the role of the activity in establishing social hierarchy (from rank (n.)).