Jesus defended his disciples gleaning on the Sabbath by retelling a story about David. Mark 2:23-28 (ESV):
One Sabbath he was going through the grainfields, and as they made their way, his disciples began to pluck heads of grain. And the Pharisees were saying to him, “Look, why are they doing what is not lawful on the Sabbath?” And he said to them, “Have you never read what David did, when he was in need and was hungry, he and those who were with him: how he entered the house of God, in the time of Abiathar the high priest, and ate the bread of the Presence, which it is not lawful for any but the priests to eat, and also gave it to those who were with him?” And he said to them, “The Sabbath was made for man, not man for the Sabbath. So the Son of Man is lord even of the Sabbath.”
It seems the point of the story compares the act of gleaning on the Sabbath with the act of eating the bread of the Presence in time of great need. It also seems that Jesus compared his authority to the authority of David. But how did the argument work exactly?
How did the Pharisees understand Jesus' answer? Does it matter that David was acting in a deceitful manner according to the story in 1 Samuel 21? The bread was specifically set aside for God and David essentially stole it. Gleaning was clearly permissible and the only question was whether it counted as work for purposes of the Sabbath law. What the disciples were doing was arguably permissible under the law, but I have a hard time seeing David's actions as justified.
Note: There's a related question about the name of the priest.