The phrase originated in ancient Greece, as the moral of Hercules and the Waggoner, one of Aesop's fables.
A Waggoner was once driving a heavy load along a very muddy way. At last he came to a part of the road where the wheels sank half-way into the mire, and the more the horses pulled, the deeper sank the wheels. So the Waggoner threw down his whip, and knelt down and prayed to Hercules the Strong.
"O Hercules, help me in this my hour of distress," quoth he.
But Hercules appeared to him, and said:
"Tut, man, don't sprawl there. Get up and put your shoulder to the wheel."
Moral of Aesops Fable: The gods help them that help themselves
However, it is often mistakenly attributed to Benjamin Franklin or believed to have biblical origin.