There's an excellent plot summary on the BBC website. (Skip to page 5 for the ending):
https://www.bbc.co.uk/bitesize/guides/zxhsyrd/revision/1
Priestley used a trick, that's been used by others many times before and since, of making the audience think that everything's clear cut and then adding a twist to confound them. (Think of the endings of movies like 'The Sixth Sense'). Throughout most of the play, nobody doubts that the inspector is real but then it turns out that there's no such person among the local police force and that none of the events seem to have happened at all. Just when it appears that it was all a hoax though, the whole sequence of events starts to occur for real. (Dickens used a similar trick in The Signalman, where it appears that he death in the tunnel that the signalman sees is only in his imagination, before it turns out that he's foreseeing his own death).