In 1325, King Alfonso declared war on the Moorish Emirate of Granada and invited other Christian kings to join him in a new crusade. This project came to nothing but Alfonso nevertheless proceeded with a campaign against the western frontier of Granada. In 1327, he captured the castles of Olvera, Pruna and Torre Alhaquime. In 1330, a second expedition was mounted to attack the castle of Teba, twenty five miles east of Olvera and a key fortification in the defences of Malaga. Alfonso established his headquarters at Cordoba and sent word to his nobles and knights to concentrate there. A contingent of five hundred knights was also sent by the King of Portugal. By the end of July Alfonso was preparing to march down the Roman road to Ecija where an advance base was to be set up.
In 1329, as Robert Bruce, King of Scots, lay dying he made one last request of his friend and lieutenant, Sir James Douglas. The King charged that, after his death, Sir James should take his embalmed heart and bear it with him on crusade, thus fulfilling the pledge that Bruce had been unable to honour in his lifetime. The chronicler Jean le Bel tells that Bruce wanted his heart taken to the Holy Land and presented at the Church of the Holy Sepulchre. The poet John Barbour says merely that Bruce wished his heart to be carried in battle against 'God's foes.' The projected campaign in Spain offered Sir James the ideal opportunity for the latter. In the spring of 1330, armed with a safe conduct from Edward III of England and a letter of recommendation to King Alfonso XI of Castile, Douglas set off from Berwick and sailed first to Sluys in Flanders.
Here, according to the contemporary Walloon chronicler Jean Le Bel, Douglas' company consisted of one knight banneret, six ordinary knights and twenty esquires. It is not clear whether the knight banneret was Sir James himself. Other knights named by the Scottish poet John Barbour included Sir William de Keith, Sir William de St. Clair of Rosslyn and the brothers Sir Robert Logan of Restalrig and Sir Walter Logan. Others alleged at one time or another to have accompanied Douglas are John de St. Clair, younger brother of Sir William, Sir Simon Lockhart of Lee, Sir Kenneth Moir, William Borthwick, Sir Alan Cathcart and Sir Robert de Glen but evidence is lacking. There appears to be no historical basis for claims that any of these men were connected with the Order of the Knights Templar, dissolved by Pope Clement V in 1312, eighteen years previously.
Le Bel relates that the Scots party remained at Sluys for twelve days, with Douglas holding court on board ship as if the late king were present. Sir James' main purpose, according to Le Bel, was to publicise his mission and find out if other knights were interested in joining the Scots expedition to the Holy Land. It may be Douglas was awaiting news of the planned crusade against Granada and on learning that, despite the withdrawal of his allies, King Alfonso still intended to go to war, he finally set sail for Spain. After a stormy passage, the party arrived at the mouth of the Guadalquivir, probably sometime in late June, and disembarked upstream at Seville.
Douglas presented his credentials to Alfonso XI. According to John Barbour, the King offered Douglas riches, fine horses and armour. Sir James declined these gifts, declaring that he and his men were prepared to offer their arms in the service of the king as humble pilgrims, seeking absolution for their sins. Alfonso accepted and assigned experienced soldiers, accustomed to the style of fighting on the Frontera, as advisors to Douglas and his fellow knights. While the Scots rested after their long voyage and waited for the expedition to depart, many foreign knights who had come to seek service with Alfonso of Castile paid their respects to Douglas, including a number of Englishmen who were particularly keen to meet the man who until recently had been their nemesis.
Alfonso formed up his army for the advance south. Barbour claims that Douglas was given command of the lead division, the 'vaward' or vanguard. It may be more likely that he was put in charge of all the foreign knights in the Castilian army.
The Christian host, its size unknown, marched to Ecija then to Osuna on the frontier. Once across the border, Alfonso continued south to the meadows of Almargen, five miles west of Teba, from where he advanced to set up camp and invest the fortress,
While King Alfonso waited for his siege engines to come up from Ecija, a Granadan relief force was forming in Malaga. This was under the command of Uthman bin Abi-l-Ulá, a Berber noble fighting in the service of the sultans of Granada, who set off with six thousand cavalry and an unknown number of infantry to the relief of Teba. Marching up the Guadalhorce valley, Uthman's force crossed over into the valley of the river Turón where they pitched camp between Ardales castle and the supporting fortress of Turón, ten miles south of Teba.
The Christian army was hampered by restricted access to water and they were forced daily to drive their livestock out of camp and eastwards down to the Guadalteba, an abundant river flowing two miles south of the castle. Uthman quickly identified this vulnerability and sent raiding parties to disrupt the watering details. Alfonso in turn set up a defensive screen of patrols to hold them off and there were regular skirmishes on the river and in the hills to the south.
It is possible that Sir James Douglas was killed in one of these encounters. The 'Gran Cronica de Alfonso XI' refers to a confrontation on the river that resulted in the death of "a foreign count... through his own error", although some commentators prefer to think Douglas died in a more decisive encounter some days later.
Alfonso had other problems. The five hundred Portuguese knights declared their term of service was about to expire and withdrew. Meanwhile, the siege engines arrived at Teba and operations began to open a breach in the walls of the castle. One night the garrison of Teba sallied out to attack the siege lines and retired leaving a siege tower in flames. Uthman too faced difficulties. He had concluded he could not defeat the Christians in open battle and so devised a stratagem to force Alfonso to abandon the siege.
Under cover of darkness, three thousand Moorish cavalry prepared to make a diversionary attack across the river while Uthman took another three thousand upstream to make a flank attack on Alfonso's camp.
At dawn, Uthman's river contingent occupied the watering grounds of the Guadalteba. Alfonso, however, having been warned by his scouts of the enemy's movements, kept the main force of his army in camp while he sent troops to check the assault developing on the river. Some argue that Douglas and his contingent must have been part of this reinforcement. With battle joined, Uthman believed that his ruse was working and, emerging from the valley where he and his men had been concealed, rode up to attack the Christian camp from the west. When he reached the col overlooking the Almargen valley he saw the camp bristling with Alfonso's men armed and ready while at the same time saw his men on the river downstream beginning to fall back. He instantly abandoned the attack and rode back to support his right wing but arrived only in time to join in the general retreat.
The Moors on the river had been unable to withstand the weight of the Christian counter-attack. When Alfonso, having seen Uthman's move east, sent a further 2,000 men to intervene, the Granadan withdrawal turned into a rout.
John Barbour, in his description of Douglas' last battle, describes a similar rout, with Douglas and his contingent pursuing the fleeing enemy closely. There is, however, no mention of the siege of Teba in Barbour's account, which describes the Christian army advancing from Seville to repel an invasion from Morocco. According to Barbour, Sir James outruns the rest of his men and finds himself far out in front with only ten or so followers. Too late, he turns back to rejoin the main body. The agile Moorish cavalry see their opportunity, rally and counter-attack. In the running fight that follows, Douglas sees Sir William St.Clair surrounded by a body of Moors, trying to fight his way free. With the few knights still with him, Douglas rides to the rescue but all are killed, including Sir William St.Clair and the brothers Sir Robert and Sir Walter Logan.
The Castilian sources do not mention any Moorish counter-attacks during the pursuit, despite the Moors' notorious capacity for turning on unwary pursuers.
The Castilian forces pursued the Moorish army back to their camp in the Turon valley. The chance of a more comprehensive victory was lost when the Christians stopped to loot the enemy tents and baggage. Despite further skirmishes, Uthman made no further attempt to raise the siege and shortly afterwards the garrison of Teba surrendered. The aged Berber general died some weeks later.
Barbour tells how Douglas' body, together with the casket containing the embalmed heart of Bruce, were recovered after the battle. His bones, the flesh boiled off them, and the casket were taken back to Scotland by Douglas' surviving companions. Douglas was buried at St Bride's Kirk, at Douglas, South Lanarkshire.
The battle was not decisive. While Teba remained secure in Castilian hands, the Guadalteba and Turon valleys continued debatable land for the next hundred and fifty years. However, in response to Alfonso XI's victories of 1327-1330, the Marinid sultan of Morocco Abu Hasan sent forces in support of Muhammad IV to re-establish control of the Straits. Gibraltar was re-captured from the Christians in 1333 but Abu Hasan's attempt to re-take Tarifa in 1340 led to his disastrous defeat by allied Christian forces at Rio Salado. This was the last intervention by North African powers in the defence of Muslim Granada.