The following passage can be found in the first paragraph of Chapter 7:
"Tom's heart ached to be free, or else to have something of interest to do to pass the dreary time. His hand wandered into his pocket and his face lit up with a glow of gratitude that was prayer, though he did not know it. Then furtively the percussion-cap box came out. He released the tick and put him on the long flat desk. The creature probably glowed with a gratitude that amounted to prayer, too, at this moment."
Here Mark Twain states that Tom experienced a moment of deep gratitude. This 'spiritual' emotion would what many would classify as a prayer. Tom, however, did not realize that this was indeed a prayer.