Check the wire harness that serves the distributor.
That is a 2 wire cable with a layer of shielding over the 2 insulated wires. Inside, one wire is ignition feed to the distributor. The other wire is the tachometer signal wire which leads away from the distributor.
If the ignition feed wire breaks, the engine will not start at all.
If the tachometer signal wire breaks, the engine will do exactly as you state........run only as long as the key is in the cranking position.
The wires usually break at, or near the distributor harness connector.
A replacement connector for the harness can be obtained from Toyota, part # 90957-U9011-71.
If you think you can splice repair the broken wire, be very careful not to let even a single strand of the shielding wire braid get into contact with your splicing. The shielding wire is grounded to the chassis and if you short the tach signal wire to ground it will still behave like it does now.
This is ONLY to be used to report flooding, spam, advertising and problematic (harassing, abusive or crude) posts.