"The Wonder Years" star Jason Hervey just learned the hard way ... never take Ambien before you get behind the wheel.
Tennessee law enforcement tells TMZ ... they got a call about a swerving pickup truck and were able to locate it. Cops say Hervey was behind the wheel and totally out of it ... slurring, red-eyed and confused.
Cops say Hervey miserably failed a field sobriety test. They searched the pickup and found a loaded handgun, but the actor had a permit. Hervey was booked for DUI and carrying a weapon while under the influence.
The incident went down back in January 2015 but it went unnoticed, until this past weekend when Hervey served 48 hours behind bars for a misdemeanor DUI charge. The weapons charge was dropped.
Jason, who played Wayne Arnold on the show, tells us he has a prescription for Ambien and stupidly took one before hopping in the truck for a quick errand, he had no alcohol in his system ... he's thankful cops got him off the road before anything really bad happened.