With a mixed army of British mercenaries and hardy Venezuelans the Liberator mounted the difficult pass which leads from Casanare up to Tunja. Samano had only three thousand troops and these he sent under the command of General Barreiro to meet Bolivar. Though the patriots were somewhat inferior in numbers and arrived on the plateau fatigued, starving, and without horses, Barreiro, not knowing their real numbers, hesitated about attacking. Bolivar was given time to rest and remount his men, and then took a vigorous offensive. His rapid movements confused the Spanish commander, and the latter allowed the patriot army to get between him and Bogotá. Thus cut off from his base, Barreiro made a desperate dash to reach the capital, but ran against the patriots posted directly across his path at Boyacá, on the 7th of August, 1819. The loyalists attacked at a disadvantage and without hope. After losing a hundred men they fled in disorder and the whole army dispersed or was captured. The way to Bogotá lay open, and Samano had no forces to defend the city. Within three days Bolivar had traversed the hundred miles from the battlefield, and Samano fled in such precipitous haste that he left behind the government archives and even the money in the treasury. A month later the whole of New Granada, except the stubbornly loyalist Pasto and the fortress of Cartagena, was free. Bolivar had himself made president and military dictator, naming Santander vice-president, and giving each province two governors, one military and the other civil, responsible directly to Bogotá. The municipal governments were preserved, and the Spanish system of taxation continued, but patriot republicans displaced loyalists in all the offices.
Bolivar soon returned to his Venezuelan headquarters on the Orinoco to fight Morillo and organise the grand republic he had dreamed of so many years. Though all of Venezuela except the Orinoco valley, all of Ecuador, and the sea-ports and southern provinces of New Granada still remained in the hands of superior Spanish armies, and although the Creole ruling class had already proved strongly prejudiced in favour of local autonomy and the tearing down of aristocratic forms, his imagination vaulted all obstacles and he planned the new state down to its minutest details. His idea was a centralised system with himself at its head as life president, backed by a hereditary senate, and ruling the three grand divisions of his empire through docile vice-presidents. But his military power and prestige were insufficient to overcome the opposition of jealous generals and ambitious lawyers. He spent the year of 1820 in futile intrigues among the politicians, and in unsuccessful campaigns against the Spaniards in Venezuela, while the patriots trembled at the news that a great army was assembling at Cadiz which would surely sweep them out of existence. A liberal revolution in Spain came opportunely to interrupt military operations.