A top-level state Senate staffer scurried out of the corruption trial of former Majority Leader Dean Skelos on Monday after being accused of coaching a witness on the stand.

Welquis “Ray” Lopez, 61, was summoned to the bench during a break in the proceedings and threatened with ejection by Manhattan federal Judge Kimba Wood.

“You’ve been nodding your head up and down and back and forth in what looks like a signal to the witness,” Wood said during testimony by a former Long Island politician who admitted serving as the bagman for an alleged payoff of Skelos’ son and co-defendant, Adam.

“If you nod your head one more time, I’m going to have court security escort you out of the courtroom.”

Sources described the former Rockville Center Republican chairman as “very close” to Skelos (R-LI), who gave him a $140,000-a-year “special adviser” job in 2011.

Despite Skelos’ resignation following his May arrest, Lopez remains on the state payroll as a $162,750-a-year adviser to Majority Leader John Flanagan (R-LI).

The shenanigans came during testimony by ex-North Hempstead Councilman Tom Dwyer, who said he handed Adam a $20,000 “referral fee” in 2013 as a favor to Charles Dorego of Glenwood Management.

Dwyer said that Dean Skelos had been pressuring Dorego to give Adam a job, but that “Charlie did not want the payment … to be associated with Glenwood.” Dorego told him: “This should get Dean off my back.”

Prosecutors later played a taped phone call during which Adam Skelos angrily invoked his dad’s influence while berating a diner owner for “squandering” the chance to buy electricity from a company Adam represented.