MR. WILLIAM JOLLY, in his “Robert Burns at Mossgiel,” on the authority of the late Mr. John Smith, Dalry, who had it from the poet himself thus tells the origin of “Tam o’ Shanter”:-
The farmer of Shanter used to visit Ayr at the weekly markets. His mare, which was left tied by the bridle to the door of the hostelry to bide the weather till her master was ready to ride, had a very handsome tail. he fisher-boys of Ayr coveted the long hair for their sea-lines; and knowing that Tam would be in no hurry to mount, helped themselves to the same, till eventually “the feint a tale had Meg to shake.” Tam, exercised as to how he should excuse himself to his wife, determined to trade on her credulity, and on his way home concocted the story that he had been pursued by witches at Alloway, hardly escaping with his life, while Maggie had lost her tail in the chase!
The story getting wind through Tam’s garrulous boasting, became, along with his own character, the groundwork of the immortal poem.
This, at least, is one account regarding its origin.