a. Only in that election did Leslie run for public office.
b. * Only in that election Leslie ran for public offcie.
c. Only Leslie ran for public offcie.
d. * Only Leslie did run for public office.
First of all, I understand a, b, and c. But the problem is d. Why is d grammatically incorrect? I think "did" in d is inserted there for emphasis as in this exmple sentence, "I do want to go to a museum."
The problem with (d) is that, for inversion to exist, the component being restricted or negated (in this case, restricted by only) does not have to be the subject, and "Leslie" is the subject.
Emphatic "did run" does not work with "only" in the subject, as Raymond suggested.
Notice what happens with "alone" depending on whether it appears within the subject or within the predicate:
1. Leslie alone ran for public office. CORRECT
2. (*) Leslie alone did run for public office. INCORRECT
3. Leslie did run for public office alone. CORRECT
Although semantically different—in (1) "alone" is synonymous with "only," while in (3) it means "unacccompanied"—, syntactically emphasis only works if "alone" does not appear in the subject, just as is the case with "only."