A blue moon refers to the presence of a second full moon in a calendar month, the third full moon in a season containing four, or a moon that appears blue due to atmospheric effects.
The calendrical meaning of "blue moon" is unconnected to the other meanings. It is often referred to as "traditional", but since no occurrences are known prior to 1937 it is better described as an invented tradition or "modern American folklore". The practice of designating the second full moon in a month as "blue" originated with amateur astronomer James Hugh Pruett in 1946. It does not come from Native American lunar tradition, as is sometimes supposed.
The moon—not necessarily full—can sometimes appear blue due to atmospheric emissions from large forest fires or volcanoes, though the phenomenon is rare and unpredictable (hence the saying "once in a blue moon"). A calendrical blue moon (by Pruett's definition) is predictable and relatively common, happening 7 times in every 19 years (i.e. once every 2 or 3 years). Calendrical blue moons occur because the time between successive full moons (approximately 29.5 days) is shorter than the average calendar month. They are of no astronomical or historical significance, and are not a product of actual lunisolar timekeeping or intercalation.
A 1528 satire, Rede Me and Be Nott Wrothe, contained the lines, "Yf they saye the mone is belewe / We must beleve that it is true." The intended sense was of an absurd belief, like the moon being made of cheese. There is nothing to connect it with the later metaphorical or calendrical meanings of "blue moon". However, a confusion of belewe (Middle English, "blue") with belǽwan (Old English "to betray")) led to a false etymology for the calendrical term that remains widely circulated, despite its originator having acknowledged it as groundless.
Percy Bysshe Shelley's poem "Alastor" (1816) mentioned an erupting volcano and a "blue moon / Low in the west." It was written at a time when the eruption of Mount Tambora was causing global climate effects, and not long before the first recorded instances of "blue moon" as a metaphor.
The OED cites Pierce Egan's Real Life in London (1821) as the earliest known occurrence of "blue moon" in the metaphorical sense of a long time. ("How's Harry and Ben?—haven't seen you this blue moon.") An 1823 revision of Francis Grose's Classical Dictionary of the Vulgar Tongue, edited by Egan, included the definition: "Blue moon. In allusion to a long time before such a circumstance happens. 'O yes, in a blue moon'." An earlier (1811) version of the same dictionary had not included the phrase, so it was likely coined some time in the 1810s. "Once in a blue moon" is recorded from 1833.
The use of blue moon to mean a specific calendrical event dates from 1937, when the Maine Farmers' Almanac used the term in a slightly different sense from the one now in common use. According to the OED, "Earlier occurrences of the sense given in the Maine Farmers' Almanac have not been traced, either in editions of the Almanac prior to 1937, or elsewhere; the source of this application of the term (if it is not a coinage by the editor, H. P. Trefethen) is unclear." The conjecture of editorial invention is further supported by the spurious explanation the almanac gave:
The Moon usually comes full twelve times in a year, three times in each
season... However, occasionally the moon comes full thirteen times in a year.
This was considered a very unfortunate circumstance, especially by the
monks who had charge of the calendar. It became necessary for them
to make a calendar of thirteen months, and it upset the regular arrangement
of church festivals. For this reason thirteen came to be considered an
unlucky number. Also, this extra moon had a way of coming in each of
the seasons so that it could not be given a name appropriate to the time
of year like the other moons. It was usually called the Blue Moon... In olden times the almanac
makers had much difficulty calculating the occurrence of the Blue Moon
and this uncertainty gave rise to the expression "Once in a Blue Moon".