Luke 15:11-24: "11 And he said, 'There was a man who had two sons. 12 And the younger of them said to his father, "Father, give me the share of property that is coming to me." And he divided his property between them. 13 Not many days later, the younger son gathered all he had and took a journey into a far country, and there he squandered his property in reckless living. 14 And when he had spent everything, a severe famine arose in that country, and he began to be in need. 15 So he went and hired himself out to one of the citizens of that country, who sent him into his fields to feed pigs. 16 And he was longing to be fed with the pods that the pigs ate, and no one gave him anything.
"17 'But when he came to himself, he said, "How many of the father's hired servants have more than enough bread, but I perish here with hunger! 18 I will arise and go to my father, and I will say to him, 'Father, I have sinned against heaven and before you. 19 I am no longer worthy to be called your son. Treat me as one of your hired servants.'" 20 And he arose and came to his father. But while he was still a long way off, his father saw him and felt compassion, and ran and embraced him and kissed him. 21 And the son said to him, "Father, I have sinned against heaven and before you. I am no longer worthy to be called your son." 22 But the father said to his servants, "Bring quickly the best robe, and put it on him, and put a ring on his hand, and shoes on his feet. 23 And bring the fattened calf and kill it, and let us eat and celebrate. 24 For this my son was dead, and is alive again; he was lost, and is found." And they began to celebrate.'"
Matthew 26:26-29: "26 Now as they were eating, Jesus took bread, and after blessing it broke it and gave it to the disciples, and said, 'Take, eat; this is my body.' 27 And he took a cup, and when he had given thanks he gave it to them, saying, 'Drink of it, all of you, 28 for this is my blood of the covenant, which is poured out for many for the forgiveness of sins. 29 I tell you I will not drink again of this fruit of the vine until that day when I drink it new with you in my Father's kingdom.'"
+++
The text from Luke is the primary source for the hymn, and it appears throughout. The passage from Matthew is referred to at the end of the third verse.
Perhaps coincidentally, the relative clause "who foolishly have wandered" bears some resemblance to "All we like sheep have gone astray" from Isaiah 53:6.