A controversial MP has been left with a hefty legal bill after a years-long legal tussle with a political adversary over a sexually explicit social media post.