In 1665-66, Lubomirski's supporters paralyzed the proceedings of the Sejm. Lubomirski himself, with the support of part of the army and the levee-en-masse (pospolite ruszenie), defeated royal forces, at the Battle of Matwy (1666). The rebellion ended with the Agreement of Łęgonice, which forced the King to give up his planned reforms and the introduction of vivente-rege royal elections. Lubomirski himself, now a broken man, died soon after.
Mid 17th century was one of the most tragic and difficult periods in the history of the Polish-Lithuanian Commonwealth. The country was devastated by several wars, such as the Khmelnytsky Uprising, and Swedish invasion of Poland. Its international position was weakened, and the chaos was deepened by the ill-functioning system of the so-called noble democracy (see Szlachta's privileges, Golden Liberty). In 1652, the Lithuanian envoy to the Sejm, Wladyslaw Sicinski for the first time in Polish history used the Liberum veto, thus voiding the new bill, which was about to be introduced. The country was destroyed by internal conflicts of the magnates, and its central institutions did not function.
King John II Casimir Vasa was aware of the condition of the Polish-Lithuanian state, and initiated an attempt to reform its institutions. In 1658, he introduced a program of improvement of the government, which stipulated, among others, voting by majority, creating a government and general tax system. The Polish Senate tentatively agreed to the reforms, creating a special commission. The problem was the issue of the royal election (see Royal elections in Poland) - the king and his supporters wanted to introduce the Vivente rege system, while his opponents disagreed.
The King and his wife Marie Louise Gonzaga began to look for supporters among the nobility and the magnates. Their opponents, acting on initiative of Habsburg envoy Franz Paul de Lisola, created their own camp, with such members as Greater Poland’s Łukasz Opaliński and Jan Leszczyński, as well as Lesser Poland’s Jerzy Sebastian Lubomirski. As a result, all attempts at the reform were defeated.
During the 1661 Sejm, the King urged all envoys to support extra taxes, needed to carry out election reform and pay the unpaid soldiers of the army. In response, the magnates opposed royal proposal, and upon inspiration of Lubomirski, a confederation called Holy Alliance was created both in the Kingdom of Poland and in the Grand Duchy of Lithuania.
Members of the confederation, which consisted mostly of unpaid soldiers, demanded their money. They were supported by some members of the nobility, who above all wanted to keep their ancient privileges, opposed any reforms and wanted to keep the so-called free royal election. Not all soldiers and nobility supported the rebellion - those who remained loyal to the King, under Stefan Czarniecki, created their own confederation, the so-called Pious Alliance.
The 1662 Sejm opposed all attempts of reform of the government, allowing only to introduce extra tax for the army. The King, however, did not give up. Aware that Jerzy Lubomirski was the main source of his problems, in 1664 accused the magnate of treason. Sejm court found Lubomirski guilty, confiscated his properties, sentenced him to infamy and ordered to leave Poland. Lubomirski left for Habsburg-controlled Silesia, where he tried to organize an army (with financial support of the Habsburgs) to invade the territories of Poland controlled by the Royal Army.
In 1665 Lubomirski announced a rebellion, and his army entered the Commonwealth. On July 13, 1666 he faced royal army under the King himself. Lubomirski’s forces were victorious. After the battle, elite regiments, consisting of best soldiers of the Polish Army were murdered by the rebels (altogether, the army lost almost 4,000 of its most experienced men). On July 31, at the village of Legowice, the King and Lubomirski signed an agreement. John II Casimir gave up his plans of a reform and declared amnesty for the rebels, while Lubomirski signed a letter of apology. In 1668, under the pressure of the Polish Parliament, the nobility and because of the sudden death of the Queen, the King abdicated.