When the train stopped, all the passengers wondered what had happened.

Literal

Train [subject-が] stopped [because-ので], passengers [topic-は] everyone, what-happened [quotative-と] wondered.

Complex sentence with embedded indirect question. どうしたのか is the interrogative 'what's the matter, what happened' + nominalizer + か. ~かと思う = 'wondered whether X.' The と is the quotative marker framing the internal question as the content of their thought.