Andrew Hay enlisted as an ensign in the 1st regiment of foot, on 6 December 1779. He served in the American Revolutionary War and was promoted to lieutenant on 21 July 1781. He transferred to the 88th Foot as captain on 24 January 1783 but when the regiment was disbanded after the war, Hay returned to the 1st Foot, maintaining the rank of captain, and inheriting seniority on 17 April 1784.
From 1787 to December 1795, a period which included the beginning of the French Revolutionary War, Hay was on half-pay, listed as a captain. He was promoted to major on 1 September 1794 but remained without a regiment until the 93rd Foot was raised, which he joined on 9 December 1795 and served with in the West Indies, until it was disbanded in 1797.
Hay became a colonel in the Banffshire Fencibles on 29 December 1798, a regiment mainly drawn from Hay's family estate in Banffshire, Scotland. Fencibles were British Army units raised for defence against the threat of invasion during times of war. They were usually temporary units, composed of local volunteers but commanded by regular army officers, and their role was usually, but not always, confined to home defence and patrol duties. While his regiment was serving in the Channel Islands, in 1801, Hay sold his home in Banffshire and moved to Fordingbridge in Hampshire. The Banffshire Fencibles were broken up in 1802 when a short-lived peace was brought about by the Treaty of Amiens.
When war with France broke out again, in May 1803, Hay was given command of the 16th Battalion of the Army of Reserve. Hay's unit transferred to the regular army on 1 December 1804 as 2nd Battalion in the Highland regiment, the 72nd Foot, when he was promoted to lieutenant-colonel. Just over 4 years later, on 19 March 1807, Hay was given command of the 3rd Battalion, 1st Foot regiment serving in Ireland, but once the British Government had made the decision to support the Spanish and Portuguese rebels against the French, Hay and his regiment were shipped out to the Peninsular.
Hay's battalion arrived in Corunna on 14 October 1808 and served under Sir David Baird. Sent in support of Sir John Moore's troops, Hay was subsequently in action during the retreat to Corunna and the battle that followed. The surviving troops were evacuated to Britain, from where Hay was sent to the Netherlands, where he took part in the unsuccessful Walcheren Campaign.
In July 1810, Hay was sent back to the Peninsular with the 3rd battalion, 1st Foot of which he again obtained command on 4 August. Hay fought at the Battle of Bussaco on 27 September, where Wellington's army drove off a superior French force under Marshal André Masséna. Promoted to major-general on 4 June 1811, Hay went on to fight in the important victories at the Salamanca on 22 July 1812 and Vitoria on 21 June 1813, in which his son, Captain George Hay received a mortal wound.
Hay served at the Siege of San Sebastián, where Leith and Oswald, the senior officers of the 5th Division were wounded, thus giving Hay command once more. Hay therefore, on 7 October 1813, led the 5th Division at the Battle of the Bidasoa when Wellington's army overran the French lines and gained a foothold in France. Hay's troops were the first to cross the river, wading across at first light and surprising the French who did not realise the water was only chest deep at low tide.
After fleeing from the Bidasoa, the French, under Marshal Soult took up a position along the Nivelle between the mountains near Ainhoa, and St Jean-de-Luz. On 10 November 1813, the 5th Division under Hay and the 1st Division under the Earl of Effingham, made a feint along the shore, allowing Wellington's Light Division to fall on the French centre while his 3rd, 4th and 7th Divisions overran the French redoubts. With the loss of the bridge at Amotz, the threat of Soult's army being cut in two forced him to fall back once more, with the loss of 4,400 men.
Soult's army entrenched itself at Bayonne, between the Nive and the Adour. Wellington, restricted in his position between the two rivers and the Pyrenees, crossed the Nive in order to gain some space. Three divisions under Sir John Hope, including the 5th under Hay, advanced towards the Adour on 9 December, whilst generals Beresford and Hill, with five divisions and three further divisions of Spanish and Portuguese soldiers, crossed upstream of Bayonne. With Wellington's army divided, Soult concentrated his army and made several attempts to overcome Hope's now outnumbered troops. The counter-attacks occurred over a three-day period starting on 10 December. After the failure of his initial assault, Soult attacked again on both the 12 and 13 December, and on each occasion he succeeded in pushing Hope back. Wellington was thus obliged each time to send reinforcements to drive the French back to Bayonne. On the night of the 12th, the river flooded due to heavy rain, and destroyed the British pontoon bridge at Villefranque, leaving Hill stranded on the north side of the river. Despite being attacked by six of Soult's divisions, Hill's line held until Wellington's 6th Division arrived four hours later, having crossed the river at Ustaritz. Beresford meanwhile had sent three divisions across the river at Villefranque, forcing the French to retreat to Bayonne. When command of the 5th Division passed to Sir Charles Colville, at the end of the year, Hay returned to his brigade.
Wellington was unable to lay siege to the city of Bayonne with Soult's army still active in the field and was thus required to divide his forces. Wellington was to use the main bulk of his army to draw Soult away, while Hope was left with the 1st and 5th divisions and a few independent brigades with which to complete the investment. Surrounding the city meant that Hope’s troops had to cross the Adour, and to this end, a pontoon bridge was constructed from locally available boats. After delays caused by adverse weather, Hope's army, which included Hay, completed its crossing on 25 February and had surrounded Bayonne by 27 February. Hope was slow to start and even by 10 April, Hope had not completed his preparations.
On 13 April 1814, news of Napoleon's abdication reached Bayonne. Hay, who was duty officer, spread the news amongst the troops; it was thought that the war would soon be at an end and the soldiers would be returning home. Early the next morning the governor of Bayonne, General Pierre Thouvenot, who had also heard the news, made a sortie, which would later be condemned by both sides as a needless waste of lives, and which proved to be the last action of the war. Hay, who was defending the church of St Etienne, died as he encouraged his men to fight to the last.
A memorial to Hay was raised at the church where he died by the officers of the 3rd battalion, 1st Foot; a government-funded memorial was later placed in St Paul's Cathedral. Hay's widow also honoured his memory with a monument in the Church of St Mary the Virgin, near the family home in Fordingbridge.