The gardener ran away because he encountered an embodiment of death. In the first part of the poem, where the gardener speaks to his master, he says that he has "encountered Death" in the garden, "among the roses." He says that Death was as "Thin as a scythe," and wore a "black coat / black gloves, and broad black hat." This description of death draws upon popular depictions of the Grim Reaper. The Grim Reaper carries a scythe with which to gather human souls and is usually dressed all in black.
The gardener explains to his master that he ran away when Death "beckoned" him to approach, and just at the moment when Death seemed about to speak. The gardener presumably thought that Death was about to tell him that his life was drawing to a close and that he had to go with him. Fearing that this is what Death had in mind, the gardener ran to his master and immediately quit his job, saying that he wanted "to see (his) sons / Once more" before he died. After this meeting with his master, the gardener likely continued running, convinced that he needed to outrun Death.
At the end of the poem, however, we learn that the gardener's fears, though of course understandable, were in fact unnecessary. We learn that Death simply wanted to ask the gardener to direct him towards his master. Death was in the garden to take the master and not the gardener.