People have already given quotes but the illustration on page 148 of the PHB makes it clearer that you only pay movement penalties for entering a square. Otherwise Regdar's final step (8 squares) would have actually cost 3 squares rather than one bringing his total to 10 squares.
The alternative is you suffer terrain penalties on leaving, which would have meant no penalty for Regdar's first step onto the difficult terrain (so it would have cost 1 square and not 2 as illustrated), so that can't be the case. It would certainly be unfair to pay the penalties both on entering and leaving he difficult terrain.
I think it has also been covered in the FAQ.... ah here we are.
FAQ Quote:
If my character moves from a square within the area of a grease spell to an adjacent square outside the spell’s area, does he have to make a Balance check?
No. As a general rule, terrain effects apply only to characters entering a square with the terrain effect, not to those leaving such a square. A creature leaving a greased square need not succeed on a Balance check to do so (of course, he must have succeeded on a Reflex save to remain standing).