The first ragamuffin was a demon. In William Langland's Piers Plowman, a long Middle English poem of the 14th century, Ragamoffyn is the name of a devil.
Merriam-Webster calls that the word's earliest known literary use, and Dictionary.com dates the Middle English form to 1350 to 1400. Nobody is sure how Langland built the name. The first part is probably related to ragged, and Dictionary.com suggests it pictured the devil's shaggy look. The second part is a puzzle. Merriam-Webster says it may come from Anglo-Norman words for a devil or a scoundrel.
Samuel Johnson did not pretend to know. His dictionary derived the word "from rag and I know not what else." Brewer's Dictionary of Phrase and Fable, quoted by Dictionary.com, offered a folk answer instead: "A muffin is a poor thing of a creature." That is a guess, not evidence.
The demon faded and the rags stayed. Merriam-Webster's first known use for the ordinary noun is 1586, and its etymology describes Ragamuffyn as a name for a ragged, oafish person. Dictionary.com notes that the word once carried harsher meanings, such as lazy, worthless or beggarly. Over time it settled on a child in ragged, dirty clothes.
In America the word got a holiday. Starting in the late 19th century, Merriam-Webster reports, children dressed up for "Thanksgiving masking," often as ragamuffins, in a parody of begging. They asked for handouts and received fruit, pennies and candy. The custom was so common that Thanksgiving was nicknamed Ragamuffin Day, and towns held parades of costumed children.
It did not survive. A 1930 New York Times headline already reported that parading Thanksgiving ragamuffins were scarce, except at the ends of the subway lines. By the middle of the century the tradition was gone. Merriam-Webster says the dressing up and begging lived on in Halloween.
The word has one more modern life. Dictionary.com's British entry lists ragamuffin as another name for ragga.
Most uses today are gentle. Dictionary.com says the word is now usually playful and affectionate, aimed at someone dishevelled. It is a long way down from hell.