Tom actually watches two different bugs instead of listening to the preacher. In chapter 5, Tom "did not enjoy the prayer, he only endured it--if he even did that much." His attention is captured by a fly on the pew in front of him. He watches it throughout the prayer and just "itches" to catch it, but he doesn't dare during the prayer. When the preacher says, "Amen," however, Tom does grab the fly, but Aunt Polly makes him let it go.
The other bug is what Tom calls a "pinchbug," a large black beetle. After having to let the fly go and still bored with the sermon, he remembers that he has the bug in a box in his pocket. The scene becomes comical when the bug bites Tom on the finger, making Tom drop it on the floor. Other churchgoers begin to notice the bug, especially when a stray dog comes into church and decides to sit down right on top of the bug. That's such a funny scene, you'll just have to read it for yourself!
While there are many bugs that appear in this story, the bug in church is a housefly. Tom watches the fly cleaning itself when he supposed to be listening to the sermon. Here is the passage from Chapter V:
In the midst of the prayer a fly had lit on the back of the pew in front of him and tortured his spirit by calmly rubbing its hands together, embracing its head with its arms, and polishing it so vigorously that it seemed to almost part company with the body, and the slender thread of a neck was exposed to view; scraping its wings with its hind legs and smoothing them to its body as if they had been coat-tails; going through its whole toilet as tranquilly as if it knew it was perfectly safe. As indeed it was; for as sorely as Tom's hands itched to grab for it they did not dare--he believed his soul would be instantly destroyed if he did such a thing while the prayer was going on.
Tom feels trapped by church. The prayer is dull and tedious to him, and he longs to be able to be active. He wants to catch the fly, who is similarly involved in a long and tedious process, but feels held back by his surroundings.