Inversion
Inversion means changing the normal word order of Subject + Verb to Verb + Subject (like in a question). We do this for emphasis, usually in formal or written English.
Negative Adverbs
When a sentence starts with a negative or restrictive adverb (Never, Rarely, Seldom, Hardly, Scarcely, No sooner), we invert the auxiliary verb and the subject.
Normal: I have never seen such a beautiful sunset. Inverted: Never have I seen such a beautiful sunset.
Normal: She had hardly arrived when the phone rang. Inverted: Hardly had she arrived when the phone rang.
After "Only"
Only later did he realize his mistake.