mid-14c., "demon;" late 14c., "a ragged lout," also in surnames (Isabella Ragamuffyn, 1344), from Middle English raggi "ragged" ("rag-y"?) + "fanciful ending" [OED], or else perhaps second the element is Middle Dutch muffe "mitten." Or, as Johnson has it, "From rag and I know not what else."
Ragged was used of the devil from c. 1300 in reference to his "shaggy" appearance. Raggeman (late 13c. as a surname, presumably "one who goes about in tattered clothes") was used by Langland as the name of a demon (late 14c.), and compare Old French Ragamoffyn, name of a demon in a mystery play. Sense of "dirty, disreputable boy" is from 1580s. Also compare ragabash "idle, worthless fellow" (c. 1600).