contrary to expectations; or so we thought, but ...
A conjunction-like expression used at the end of a clause to indicate that what follows is contrary to what was just stated or assumed. Often translated as 'but contrary to expectations' or 'however, it turned out that...'. Typically used in written or formal speech.
彼は来ると思いきや、姿を見せなかった。
I thought he would come, but contrary to expectations, he didn't show up.
We thought we could win easily, but we were forced into an unexpectedly tough fight.
と思ったら can express a similar contrast but is more colloquial and often used for immediate, surprising changes. 思いきや is more literary and emphasizes the unexpected outcome.
Derived from the classical Japanese verb 思ふ (omofu, 'to think') in its continuative form 思ひ (omohi) combined with the particle き (ki, past recollection) and the interrogative particle や (ya). Literally 'did I think?', it evolved into a fixed expression meaning 'contrary to what one thought'.