My truck is doing something similar. When wheeling I do not turn the truck off. If around town I rock the gear selector back and forth a few times remove the key count to ten try to start the engine repeat.
I believe the problem is a sensor on the tranny going bad do not remember the name but the price was a couple hundred bucks.

~ Jon


95 Montero SR
33 x 12.50
Aussie Locker
OME Heavy Duty Coils & Torsion Bars
ARB Front Bumper
76" Trail Gear Rock Sliders
XRC-9.5K Winch