The scary face on a cathedral roof started out as plumbing.
A true gargoyle is a carved waterspout. Rain runs off the roof into a trough along the back of the figure and out through its open mouth, which throws the water clear of the wall. That keeps the masonry and mortar from eroding. Builders often put several on one building to split the flow.
The word says the same thing. It comes from Old French gargoule, a conduit for water, recorded in 1294. Wikipedia gives the date 1294. It joins garg-, which Etymonline says is perhaps imitative of throat sounds, to goule, a dialect word for "mouth" from Latin gula, "throat." Etymonline reports the word in Middle English in the late 1200s. It is a close relative of the verb gargle, which arrived in the 1520s from French gargouiller, "to gurgle." A gargoyle is, literally, a gurgling throat.
Spouts shaped like animals are far older than the Middle Ages. Egyptian, Greek, Etruscan and Roman builders all used them, and Greek temples had lion-headed ones. According to Viollet-le-Duc, the earliest known medieval examples are on Laon Cathedral, around 1200 to 1220.
The French legend adds a monster. Saint Romanus, bishop of Rouen in the 7th century, is said to have freed the region from a dragon called La Gargouille. In the story, its head and neck would not burn, so the head was mounted on the cathedral wall to ward off evil spirits. The legend gives the creature the same name as the word, but Wikipedia says the story sprang up around the name. Neither source dates the legend, so it looks like a tale built around an existing word.
Strictly, a carved figure that carries no water is not a gargoyle at all. Such purely decorative figures are called grotesques or chimeras, though most people now call them all gargoyles.