Subaru won't start

In the couple of days since my last oil change, my 2003 Subaru Legacy (161K miles) won’t start after sitting for some time. It turns over and runs for literally one second, then dies. It is standard transmission. If I have it out of gear and apply gas, it will start and stay started, but if I take my foot off the gas, it stops. I don’t have to apply a lot of gas (not floor it). Once it is warmed up it runs fine. It seems to start fine if it sits a little while, but anything over an hour, and it doesn’t start. Any ideas? One place I read said it could be the security system, with my key needing to be re-programmed. Other possibilities seem all over the map.

Could be a couple of things. One of the easier things to check is the Mass Air Flow sensor.
You basically unplug it and then start it so see if wants to stay running.

Do you know where it is located on your car?
I can probably find a picture for you, if you don’t know.

Edit: forgot to ask - is the check engine light on?

Number 5 in the drawing.
The check engine light may come on but that’s normal. Plugging it back in and leaving the battery disconnected for a while will reset it.

My guess would be a vacuum leak or problem with the Idle Air Valve circuit.

Could also be the temperature sensor.

Edit: although, now that I think about it, a bad temperature sensor on a Subaru usually shows itself by starting and stalling. No amount of throttle will keep it running.
Eventually it will start but that just means it gets into limp mode so it probably isn’t the temp sensor.

If you think about what inputs are used or not used during cold starting and then what inputs are used after closed loop or after warmed up, it’ll narrow it down. I’d be looking at the engine temp sensor too.

Try leaving the key in the on position 10 seconds before starting, If it works fine probably a new fuel pump.

Read your owners manual about the alarm system.

Try replacing the fuel filter if that hasn’t been done in a while.

Thanks for all the ideas. I will try them today, and post what I find. The check engine light is not on. And I had thought this morning when I woke up that I should look at the manual about the security system! Silly me. Thanks again!