As the former capital of the Roman Empire, Rome was an obvious choice as the capital of Italy when the Kingdom of Piedmont-Sardinia started unifying the Peninsula in the XIX century.
There was just a small problem: Rome was the capital of the Pontifical States.
The Papal Army was not a problem, nor was the influence of the Church over the Italian people. The Italian public was largely hostile to the Pope, and so were the people of Rome, exasperated by an antiquated and oppressive Government.
However, the Pope was protected by the European Catholic Powers: France, Austria and to a lesser degree Spain. In theory, they were protecting the independence of the Holy See. In practice, this was a way to keep the Peninsula under their sphere of influence.
The showdown came in 1870, when Austrian influence had vanished and France was busy trying to repel the Prussian-German attack. After a last attempt to persuade the Pope, the Italian Government sent in its crack troops, the bersaglieri, a corps established to allow Italy to take part in the Crimean War. Rome was defended by the Zouaves, foreign Catholic volunteers enlisted by the Holy See. The city quickly fell, however.
The Pope was left unmolested in the Vatican, but he severed any tie with the Italian State, excommunicated the Italian Government and forbade Italian Catholics to vote or be candidates in the Italian elections. The rift was healed only in 1929, when Mussolini’s Government signed the Lateran Pacts establishing the tiny Vatican State.