A spelling contest.
The term 'bee' has been used in the USA with the meaning of 'gathering', either for work, pleasure or competition, since the mid 18th century. The first such usage was the name 'spinning-bee', as in this example from The Boston Gazette, 1769:
"Last Thursday about twenty young Ladies met at the house of Mr. L. on purpose for a Spinning Match; (or what is called in the Country a Bee)."
Bees got their name by quite a roundabout route. The Middle English word for a prayer was a 'bene', from which we derive words like 'benefit'. This migrated to 'boon', with the meaning of 'a favour granted'. The English Dialect Dictionary, 1905, records the country term 'boon' as meaning "voluntary help, given to a farmer by his neighbours, in time of harvest, haymaking, etc".
Migrants from England to the USA would have taken the term 'boon', which was also spelled 'been' or 'bean', with them. Communal activities were an essential ingredient of survival in frontier America and the word would certainly have been called on there. The imagery of the social and industrious nature of bees was sufficient to change 'beens' into 'bees'.
Many of the activities where people congregated to undertake communal work became known as bees of one sort or another - 'husking-bees', 'quilting-bees', 'barn-raising-bees'. A less pleasant form of assembly was the hanging or lynching bee. A reference to such was made in The Fort Wayne Weekly Sentinel in August 1874. The paper reported a story of an incident in Maysville, Indiana, in which a case of mistaken identity almost resulted in a lynching:
"And he came very near being the chief attraction at a Lynching Bee."
The best-known 'bee', and the one that remains in common use, is the 'spelling bee'. Such events were originally called simply 'spelling-matches' but, being social gatherings, they came to be referred to as 'spelling-bees' by the early 19th century. The first reference I can find to the expression 'spelling-bee' in print is in The Knickerbocker, or New-York Monthly Magazine, April 1850:
"Those who have attended a 'spelling-bee' - and what reader who ever went to a district-school in the country but has attended them?"
It is clear that the term was well-established by 1850, as the citation suggests that the tests had then been in use for some years.
Sometimes the tests were simply called 'spellings' rather than 'spelling-bees'; for example, this line from Oscar L. Jackson's 1860 reminiscences The Colonel's Diary:
"The boys were anxious for a spelling in the evening."
The popularity of spelling-bees in the USA was partly due to literacy being encouraged as a patriotic duty and partly to the widespread use of Noah Webster's American Spelling Book, which was first published in 1783. Webster is now best known for his American Dictionary of the English Language, but his spelling book, popularly known as the Blue-backed Speller, has possibly been more influential. This report from The Decatur Daily Review, May 1899, acknowledges Webster's significance:
"After the regular business meeting of the Baptist Senior Endeavor society Monday night the members put aside dull care for an hour and had fun with the English language in an old fashioned spelling bee. If the ghost of Noah Webster was watching the scene he probably congratulated himself that he had not lived in vain."