I almost lost my job trying to help her.

Literal

Her help [purpose-ために] almost job [object-を] lose [near miss-ところだった].

危うく~ところだった means 'almost did X' — expressing a close call. 仕事を失う means 'to lose one's job.' ために marks the purpose (helping her) that nearly caused the consequence.