We arrived at the station just as the train was about to leave.
Literal
Train [subject-が] depart [about-to-ようとしている] time, we [topic-は] station [at-に] arrived.
A subordinate-clause frame: ~ようとしているとき ('at the time when X is about to happen'). ~ようとしている is the present-continuous form of the volitional + とする 'about to' pattern. とき ('time, moment') uses its bare nominal form (without に) here, which is fine for topic-framing.