Verb[た] + あげく(に)
Noun + の + あげく(に)
あげく (also written as あげく挙げ句) expresses the idea that after a long process, effort, or struggle, something – usually an undesirable or disappointing result – occurs. It translates to "in the end," "after all that," or "to end up (doing)." The nuance is that the speaker went through considerable trouble or a prolonged situation before arriving at the final outcome.
あげく attaches to verbs in the past tense (た form) or to nouns followed by の:
The optional に after あげく does not change the meaning.
あげく almost always implies a negative or regrettable outcome. The first clause describes a prolonged or difficult process, and the second clause describes an unfortunate conclusion. It would be unnatural to use あげく when the result is clearly positive.
Compare with けっきょく結局 (けっきょく), which simply means "in the end" without necessarily implying a prolonged struggle, and すえに末に (すえに), which is similar but can be used for both positive and negative outcomes. あげく is specifically weighted toward negative results after prolonged effort.
あげく often appears with words emphasizing the extent of the struggle, such as さんざん散々 (さんざん – thoroughly/terribly), さんざんまよった迷った, ながい長い, or other expressions of duration and difficulty.