In 1809 the 57th Foot was sent to Portugal as reinforcements for the Anglo-Portuguese Army under the Duke of Wellington, during his second attempt to drive the French out of Spain during the Peninsular War. MacGregor's regiment disembarked at Lisbon about three months into the campaign, on 15 July. By September it was garrisoning Elvas, near the frontier with Spain. Soon thereafter MacGregor was seconded to the 8th Line Battalion of the Portuguese Army, where he served with the rank of major from October 1809 to April 1810. According to Michael Rafter, author of a highly critical 1820 biography of MacGregor, this secondment came after a disagreement between MacGregor and a superior officer, "originally of a trivial nature", that intensified to such an extent that the young captain was forced to request discharge. This was promptly granted. MacGregor formally retired from the British service on 24 May 1810, receiving back the £1,350 he had paid for the ranks of ensign and captain, and returned to Britain. The 57th Foot's actions at the Battle of Albuera on 16 May 1811 would earn it considerable prestige and the nickname "the Die-Hards"; MacGregor would thereafter make much of his association—despite having left the regiment one year prior.