The Monroe Doctrine, issued by President James Monroe on 2 December, 1823, was specifically intended to dissuade European nations from imposing - or re-imposing - colonial rule over any territory within the Americas / Western Hemisphere.
The specific reasons for the issuing of the Monroe Doctrine in 1923 was the potentially explosive combination of the recent winning of independence by the majority of European colonies in Latin America and the stated goals of the victors of the Napoleonic Wars in Europe.
When, in 1807-1808, Napoleon Bonaparte's troops took control of the Kingdoms of Portugal and Spain, these kingdom's colonies in the Americas were given the opportunity to make their bids for independence (Brazil, a colony of Portugal, followed a unique path to independence. The royal family fled Portugal and set up court in Rio de Janeiro. When they returned to Portugal in 1821, Prince Pedro remained in Brazil and, in 1822, declared for independence, becoming the first Emperor of Brazil, Pedro I).
The colonial possessions of the Kingdom of Spain in the Americas constituted the majority of the Western Hemisphere, reaching from Patagonia in the southern-most tip of South America to the Pacific Northwest in North America. With the exception of Brazil, nearly all of South America was possessed by Spain. Nearly all of Central America was also owned by Spain. The Spanish colony of 'New Spain' included all of Mexico and, among others, the current States of California, New Mexico, and Texas. Within the Caribbean, Spain possessed the islands of Cuba and Puerto Rico (other islands in the Caribbean were colonies of France, Great Britain, and the Netherlands).
With the exception of Cuba and Puerto Rico, all of Spain's colonies in the Americas eventually achieved their independence by the 1820s, usually through bloody wars of revolution. Inspired by the examples set by the Revolution in the British colonies that produced the democratic government of the United States and the Revolution in France that overthrew that nations monarchy, the newly independent colonies of Spain (unlike Brazil) rejected monarchy and proclaimed themselves republics (with the temporary exception of Mexico).
In contrast to the flourishing of democratic government, however flawed, in the Americas, Europe, in the wake of the French Revolution and Napoleonic Wars, experienced a re-assertion of conservative monarchy. After the first defeat and abdication of Napoleon in 1814 (Napoleon managed to escape captivity and regain power in France in 1815, only to be decisively defeated at the Battle of Waterloo), representatives of the victorious kingdoms met in the Austrian capitol of Vienna. At this, the 'Congress of Vienna', the representatives of the Kings of Great Britain, Prussia, and Spain, the Emperor of Austria, and the Czar of Russia all tried their best to restore Europe to its state before the French Revolution had taken place. This meant loudly condemning democratic government and pledging to support one another in defending monarchy.
Although the United States chose not to directly intervene in the wars of independence in Latin America, the nation's own recent history of fighting against the monarchy of Great Britain to achieve independence and establish a democratic government naturally meant that the sympathies of the people of the United States were with their fellow 'Americans' in Latin America. The United States government demonstrated these attitudes of sympathy by officially recognizing the newly liberated Spanish colonies as sovereign nation-states.
Spain did not abandon their colonies in the America willingly. Following the end of Napoleonic Wars in Europe, Spain dispatched large numbers of veteran troops to Latin America in an effort to crush the Revolutionaries and restore full control over their colonies. Although these efforts were ultimately unsuccessful, the stated goal of the European kingdoms represented at the Congress of Vienna, to fight to defend monarchy when challenged by the supporters of democracy, suggested to President James Monroe and his Administration that there was a real danger that European kingdoms might be tempted to attempt to re-impose colonial rule over portions of newly independent Latin America.
This, then, was the reason President Monroe chose to issue his 'Monroe Doctrine' in 1823.