Writing began as scratching, and graffiti is the word that never forgot it.
The ancestor is the Greek verb graphein, which meant to scratch or carve before it meant to write. Early writing was literally cut into clay or stone. That root also gave English the ending -graphy, as in photography and geography, and Etymonline traces it to a Proto-Indo-European root meaning "to scratch, carve."
Italian took the idea and made it smaller. Graffiare is "to scribble," graffio is a scratch or scribble, and graffito is its diminutive, a little scribbling. The plural, graffiti, is the form English borrowed.
It arrived in 1851, and it had a specific job. English used it for the ancient inscriptions found on walls in the ruins of Pompeii, scratched messages that include, as Wikipedia notes, a lament over a frustrated love. Etymonline notes that such writing appears in many ancient places, but the habit was especially popular among the Romans. Wikipedia adds an even earlier example, from the Greek island of Astypalaia around 500 BC. It notes that in Rome graffiti was a common form of communication and generally not treated as vandalism.
By 1877 the meaning had widened. English applied the word to recent crude drawings and scribbling in public places, and a term from archaeology became an everyday word.
The modern movement came later. According to Wikipedia, graffiti as we know it began in New York's subways and in Philadelphia in the early 1970s, with early writers such as TAKI 183 and Cornbread. Wikipedia says a 1974 essay, "The Faith of Graffiti," used the word for the movement and it stuck. The practice of the tag, a signature written on a wall, grew up in Philadelphia and New York in the 1960s.
One grammar note. Strictly, graffiti is plural and graffito is the singular, but Wikipedia observes that graffiti is usually used for both and graffito is rare outside archaeology.
So a word for ancient scratches on Roman walls now describes spray-painted murals. Its meaning moved from archaeology to street art without losing the scratch.