まさか + [sentence (plain)] + とは思わなかった まさか + [sentence (plain)] + はずがない / わけがない まさか + [sentence] + ないだろう まさかの + [noun]
まさか says something is beyond belief: "no way", "surely not", "I never thought". It opens the sentence, and what follows is either a surprise that has already happened or one the speaker refuses to believe will.
For something that did happen, まさか pairs with とはおもわなかった思わなかった, "I never thought that…". The clause before とは is in the plain form.
For something that hasn't happened, まさか comes with a negative guess: ないだろう, はずがない or わけがない. The speaker is sure it won't happen, and slightly afraid it might.
As a question, まさか voices a suspicion the speaker hopes is wrong.
Before a noun, まさかの means "unexpected", and まさかのとき時 is "an emergency".