通りすがりの 'passing by / passerby' is a relative clause formed from the compound verb 通り過ぎる variant. ~てもらえ (potential of ~てもらう) means 'was able to have them notice (for our benefit).' 事なきを得る is a set expression meaning 'to get through without incident / be saved from disaster.' こうして 'in this way' wraps up a narrative sequence.