I'd been trying not to think about it as much as possible, but the moment you become aware of it, a lonely feeling starts creeping in on you.

Literal

As-much-as-possible think-[volitional-negative-まい] [quot-とは] was-thinking [but-のだが], self-awareness [obj-を] do-[completion-てしまう] [when-と] at-that-moment lonely-[like-ような] feeling [also-に] come-to-become.

考えまい uses the volitional-negative auxiliary ~まい — a classical-leaning form meaning 'I won't X / let's not X / (I) resolve not to X.' 途端に '(the) moment X, then Y' is a fixed adverbial for immediate temporal succession. 侘しい (わびしい) is a literary adjective for a quiet, lonely, desolate feeling — often carrying aesthetic weight in Japanese poetry (the root of 侘寂 wabi-sabi). ~てくる here is the change-over-time 'start to / come to X' sense.