After Jesus fed the five thousand on five loafs, the people began moving to make him their king. Jesus, wanting to save the Apostles from being too ambitious, made them head off in their boat, while he went up the mountain to pray, and the throng made their way around to Capernaum.
Meanwhile, the Apostles in the middle of the lake, were hit by a storm that they felt would kill them. It was then that Jesus came to them, walking on the water.
That story is actually a parable, with the storm standing for a sure threat of death. If we have Faith when we are about to die, Jesus will come walking to us over the waves of death.