Roots of the first invasion
In 2013, Ukraine was in talks with the European Union about an trade association agreement leading to the process of membership of the European Union. That was completely against Putin plan as he wanted to have a bloc on the western border of his union, which only includes Belarus. He needed Ukraine to have a full closed bloc. The Eurasian Union the way Putin had in mind threatened to be a failure.
In November 2013, Putin began actively to meddle in an attempt to jeopardize the whole process. He pressured the then president of Ukraine, Viktor Yanukovych not to sign any agreement but also tried to lure Yanukovych by going on a gas gambit despite that he had already cut off gas supply to Ukraine before, in 2006 for example. The weaponization of debts on gas bills and the threat to cut off Ukraine from oil and gas (again) were used to put the pressure high. Yanukovych had no other choice than not to sign the agreement meant to gradually integrate with the EU . Putin won the first phase of his political war against the European Union
However, Putin's intrigues only inflicted massive anger prompting hundreds of thousands in Kiev to protest against Yanukovych and his government, which turned in the biggest protest the country ever have known. The protest faced a bloody crackdown with hundreds of protesters killed many by Berkut (= riot police) sniper gunfire.
On February 22, 2014, the Ukrainian parliament voted to remove him from his post and schedule new elections on the grounds that he "has restrained himself from performing his constitutional duties" and effectively resigned, rather than by following the impeachment process for criminal acts under Article 108 of the Ukrainian constitution. Two days later an warrant had been issued for his arrest. Yanukovych was accused of mass killing of civilians. He fled to the other side of the border to Rostov-on-Don in Russia.
The development was a defeat for Putin as he saw a new Ukraine but without a pro-Russia regime. In response, he scrapped the Budapest Accord in order to delegitimize the sovereignty and security of Ukraine signed by the person who appointed Putin as his success: Boris Yeltsin.
On February 24, 2014 he attacked Ukraine and invaded Crimea in order to steal it.