On who's behalf did they gain this security? Certainly not on behalf of their citizens or their country which they tried betraying to the Russians. A corrupt president betraying his country to a hostile entity, and then inviting armed forces of said hostile entity to fire at protesters isn't a country showing ''agency''. Yanukovitch wasn't representing Ukraine during Maidan. That was the whole problem Ukraine had with him.
The more sympathetic explanation for Yanukovich was that he was representing Ukraine by cancelling plans for a trade deal with Europe because Russia had threatened severe repercussions. It was known that Russia was directing heavy economic pressure on Ukraine, but it's entirely possible that Russia had also told Yanukovich that Russia might take military action against Ukraine. He might not however say that to Ukrainians, because to openly admit to Ukrainians that the country was in effect a vassal state of Russia would have serious downsides. It would make Russia much more unpopular in Ukraine, which could be bad for Ukraine due to general diplomatic friction, and would certainly be bad for him as a pro-Russia politician.
However, there are then all sorts of middle grounds between Yanukovich as a politician honestly trying to do the best for his country and as a Russian stooge, and I suspect it is somewhere in that middle ground. I wouldn't be surprised if in the final analysis, it wasn't so much about national interest as that he was heavily corrupt and probably saw Russia as the source of his and his party's benefit.