Leaving Japan takes as much paperwork as arriving, and most of it has to be done before you go. Several of these cannot be done from abroad.

A month or two before

In the last two weeks

At the airport

After you leave