We invert the subject and auxiliary verb in the sentence to give emphasis. This happens:
1. After certain expressions when they are at the beginning of a sentence.
In / Under no circumstances
Scarcely (ever)… when
Hardly (ever)… when
No sooner… than
Not only… but also
On no occasion
In no way
Nor / Neither
Not even once
On no account
Only in this way
Rarely do we see him these days.
No sooner had we got into the house than he phoned us.
2. When the following expressions begin a sentence, we use inversion in the main clause.
Only after, only by, only if, only when, not till / until, not since.
Only after he had graduated, did he start looking for a job.
Only if you invite her, will she come to your party.
Not until all tests had been completed, were we told the results.