Military service 1914–1919
Having joined the General Reserve of Officers immediately following Britain's declaration of war against Germany, he was appointed a temporary Captain in his old regiment, the Irish Dragoons, in February 1915. By May 1916 he had been promoted Major and was second-in-command of the 7th Battalion of the Norfolk Regiment when engaged in heavy fighting during the Battle of the Somme. He was advanced to Lieutenant-Colonel in the same year and in September was given command of the 2nd/14th London Regiment, the London Scottish. In November he led this Territorial battalion, part of the 60th Division, to reinforce the allied army on the Salonica front.
The battalion saw action during the Second Battle of Doiran, and Ogilby was mentioned for gallantry in General Milne's half-yearly despatches of March and October 1917. By the latter date he had already spent three months with his unit in Egypt and Palestine; he was mentioned for his service in the latter theatre in General Allenby's despatches of January 1918. He was awarded the Distinguished Service Order (DSO) in the same month.
As part of 60th Division, Ogilby's battalion saw considerable action in Palestine (where its soldiers accounted for two of the three Victoria Crosses won by men of the London Scottish) and made an important contribution to carrying the British line forward from Beersheba to Jerusalem. After the Battle of Jerusalem the battalion, headed by its pipes, was the first to enter the city as a formed body. General Chetwode later recalled it was the first unit of XX Corps to regain parade smartness after shaking off the mud through which it had to fight during the final stage of the battle.
St Andrew's Church, Jerusalem was later built as a tribute to Scottish soldiers who fell in the Palestine campaign, and Ogilby was present when the memorial for the London Scottish casualties was unveiled there in 1934.
Leaving Palestine and returning to France in June 1918, Ogilby's battalion was in action during the Advance in Flanders as part of the 30th Division, contributing to the capture of the Dranoutre Ridge in August. For his "very fine work" in the latter operation Ogilby was mentioned in Field Marshal Haig's despatches and awarded a bar to his DSO. The award citation referred to the "particularly fine example of energy and fearlessness he set to his men at a critical time" and to the value of his personal reconnaissance which led to adjustment of his dispositions and enhanced ability to withstand counter-attack.
Ogilby's battalion was attempting to bridge the River Scheldt when the November Armistice was announced. He relinquished his command in January 1919 and was awarded the Belgian Croix de guerre in March. He retired from Territorial service in July, retaining his rank of lieutenant-colonel.