Here’s what Wikipedia has to say about it, and it looks pretty accurate to me. I remember reading all those stories, way back when.
Origins of Mary Sue
The origins of the first story with the Mary Sue archetype are unknown. Possible candidates are the brilliant Vulcan dancer T'Rruel, who became Spock's second wife in Jacqueline Lichtenberg's Kraith story Spock's Affirmation, first published in the fanzine T-Negative in 1967; also in T-Negative, the heroines of the "Dorothy and Myfanwy" series written by Dorothy Jones Heydt; and especially Lorna Mitchell, the time-traveling earthwoman who became Ambassador Sarek's second wife in Sharon Emily's amateur novel The Misfit. Lorna is often cited as the first Mary Sue, although Sherrith MacRaith (who appeared about the same time in Sheryl Roberts' Kraith-based novella The Affirmation) is a far more likely candidate.
The story that gave her a name was "A Trekker's Tale" by Paula Smith, published in the Star Trek fanzine, Menagerie in 1973. It featured a character named Lt. Mary Sue. This story, written as a piece of satire, mocked a type of fan fiction featuring unbelievably competent and beautiful female characters. Fanfiction analyst Laura Hale described them as "female characters that were involved with Kirk or Spock, Bones or Sulu, characters that could and did save the day when the heroes could not."
And here’s “A Trekker’s Tale”, the story which gave a name to 10,000 OFCs...!
(Just X out of the annoying ad box that covers up most of the screen and you’ll be able to read the story.)