On 20 March 1917, McNamara, flying a Martinsyde, was one of four No. 1 Squadron pilots taking part in a raid against a Turkish railway junction near Gaza. Owing to a shortage of bombs, the aircraft were each armed with six specially modified 4.5-inch howitzer shells. McNamara had successfully dropped three of his shells when the fourth exploded prematurely, badly wounded him in the leg with shrapnel, an effect he likened to being "hit with a sledgehammer". Having turned to head back to base, he spotted a fellow squadron member from the same mission, Captain Douglas Rutherford, on the ground beside his crashlanded B.E.2. Allied airmen had been hacked to death by enemy troops in similar situations, and McNamara saw that a company of Turkish cavalry was fast approaching Rutherford's position. Despite the rough terrain and the gash in his leg, McNamara landed near Rutherford in an attempt to rescue him.
As there was no spare cockpit in the single-seat Martinsyde, the downed pilot jumped onto McNamara's wing and held the struts. McNamara crashed while attempting to take off because of the effects of his leg wound and Rutherford's weight overbalancing the aircraft. The two men, who had escaped further injury in the accident, set fire to the Martinsyde and dashed back to Rutherford's B.E.2. Rutherford repaired the engine while McNamara used his revolver against the attacking cavalry, who had opened fire on them. Two other No. 1 Squadron pilots overhead, Lieutenant (later Air Marshal Sir) Roy "Peter" Drummond and Lieutenant Alfred Ellis, also began strafing the enemy troops. McNamara managed to start the B.E.2's engine and take off, with Rutherford in the observer's cockpit. In severe pain and close to blacking out from loss of blood, McNamara flew the damaged aircraft 70 miles (110 km) back to base at El Arish.
Having effected what was described in the Australian official history of the war as "a brilliant escape in the very nick of time and under hot fire",McNamara "could only emit exhausted expletives" before he lost consciousness shortly after landing.