In 1807, an elegant stranger appeared at the Escorial, the vast palace outside Madrid that was home to the Spanish royal family. He claimed to be a wealthy 'man of sciences' who was looking for the restoration of an ancestral title. While out taking her daily constitutional, Queen Maria Luisa noticed this dashing young man driving past in his gilded carriage.

The queen had a fondness for handsome men. She was already cheating on her husband King Charles IV with his prime minister, Manuel Godoy.

And it wasn't long before she had welcomed the newcomer into her boudoir. What the queen didn't realise was that her new lover was not a wealthy French aristocrat but James Florence Bourke, an Irish spy working for the British government.

"I was acquainted with the character of women in general, but particularly with hers," he boasted in a report to his London spymaster.

"Consequently I was honoured with her personal society in the most private manner."

Bourke's mission was to force the highly dysfunctional Spanish royal family and its government to ally with the British interest. He had already discovered from the French ambassador at the court that Napoleon was about to invade Spain. Within days of seducing the queen, Bourke realised that the real power at court was Godoy and set about trying to gain his confidence.

Once he was alone with Godoy, he produced a note from a secret compartment in his snuff box which confirmed the French invasion. However, Godoy was a vain, corrupt man and refused to take the note. Bourke, revealing his true identity, threatened him with a pistol and "told him with some vehemence" that it would be in his interests to read it.

The threat did the trick. Godoy persuaded his lover the queen, and her cuckolded husband, that it would be in their interests to work with the British.

"From that moment I directed all the operations of the court," Bourke wrote. "I was presented to the queen and king as the savior of the crown."

But just who was this 18th- century superspy? Born in Lorient in Brittany, France, on May 5, 1771, James Bourke was the son of Richard Bourke, a Jacobite refugee from Lacken in Co Mayo who had served in one of the French army's Irish regiments.

James and his brother Jean-Raymond-Charles Bourke also joined the French army.

While Jean-Raymond-Charles rose through the ranks to become a general under Napoleon - the name Bourke is inscribed on the Arc de Triomphe in Paris in recognition of his victories - James's career in the French army was over in 1793 when his regiment was captured by the British.

Realising they had a valuable asset on their hands, the British turned Bourke into one of their agents. Bourke became adept at his trade. He had a natural facility for languages and employed many different personas to elicit information.

On various occasions he passed himself off as a French philosophe, a Prussian officer and a sailor from Trieste.

He enjoyed employing many of the methods that have become familiar thanks to the modern spy thriller. He used lemon juice to write invisible letters, made use of false compartments and was adept at concealing weapons. Much like a certain Ian Fleming character with the same initials, his powers of seduction were his most powerful weapon.

He used them to good effect when the British sent him to South America to report on conditions in Buenos Aires. Before travelling to the city, he stopped off at Rio de Janeiro where the Portuguese royal family was living in exile. Having already seduced her mother Queen Maria Luisa, Bourke turned his attentions to Princess Carlota, the Spanish-born wife of the Portuguese prince regent who had ambitions to rule over her own South American empire.

But she had a rival, Ana O'Gorman, the beautiful French wife of one of Bourke's old acquaintances, Thomas O'Gorman, a merchant from Ennis who was based in Buenos Aires.

Ana was a beautiful woman who provoked scorn and jealousy in equal measure because of her scandalous affairs. Revolutionaries, diplomats, soldiers and spies mixed at glamorous parties. In 1805, she became acquainted with James Bourke. They soon became lovers.

It is possible that Bourke persuaded Ana to work for the British government, which was desperate to wrest control of South America's lucrative markets from the Spanish in order to open them to British-manufactured goods.

Four years later, Ana O'Gorman was the mistress of Santiago de Liniers, the viceroy of Buenos Aires. Liniers had become a hero in 1807 for thwarting two British invasions of the city. His rivals suggested that Ana exerted political influence over Liniers. It is indeed possible that Bourke had recruited Ana O'Gorman as a British spy.

In Rio, Princess Carlota was fiercely jealous of Ana's influence and power. Bourke attempted to reassure her. "I acquainted with what I knew of said woman and that I would endeavour to remove her," he wrote.

When Bourke arrived in Buenos Aires, he accused Liniers, a Frenchman, of working for Napoleon, and made insinuations about Ana.

Liniers was furious and ordered Bourke out of Buenos Aires.

Eventually Liniers, who was coming under pressure from both conservatives and liberals, gave way to a Spanish-appointed viceroy, but not before deporting his mistress to Brazil.

Neither were Princess Carlota's ambitions achieved. In May 1810, the last Spanish viceroy was swept away and the path became clear for those seeking to achieve an independent Argentinian republic.

Bourke retired in 1826, but as is often the case for those engaged in undercover work, his efforts went largely unrewarded and unrecognised.

He died in Lorient, France, in 1841.

Tim Fanning's book 'Paisanos: The Forgotten Irish who Changed the Face of Latin America' is published by Gill, at €24.99.

Sunday Independent