Use of "that": Must or optional?

Hi

I would like to know if the use of THATs in the given sentence is a must or optional.

1- It was not until then that I realised that I had been rooked.

Tom

The first “that” is essential, the second one is optional.

“It was not until then that I realised I had been rooked” has the same meaning.