Shane Dowling (40) and a woman companion were caught by gardai after they emerged into the empty bar and helped themselves to drinks, setting off the alarm.
He admitted the offence, but denied that he had hidden in the toilets, claiming instead that he and the woman had fallen asleep in the smoking area of the pub.
Fining him €200, Judge Anthony Halpin remarked that this was an "incredible story that Hans Christian Andersen would not have come up with."
Dowling, with an address at Carrickmount Drive, Rathfarnham, pleaded guilty to trespassing with intent to commit a theft.
The incident happened at the Fortunestown Inn, Fortunestown Lane, Tallaght, on March 14, 2011.
The court heard gardai were on patrol at 2am on March 14, 2011, when they received a report that the interior alarm at the pub was going off.
They looked inside and could see "persons moving about" inside, Sgt Bernard Jones said.
They entered and saw the accused with a woman in his company. They were behind the counter taking drink from bottles on the shelves.
When they saw the gardai they tried to "make a run for it" but were caught in the hallway.
The court heard the pair had stayed in the toilets when the pub was being locked up by staff, who set the alarms for the night.
Nobody was living over the pub, which was empty at the time.
Dowling had two previous convictions.