The president of the New York Public Library was busted for drunken driving after careening in reverse down an East Harlem street Sunday in a bid to maneuver around the marathon — but ended up slamming his luxury car into a sanitation truck.

An inebriated Dr. Anthony Marx, 52, just missed one truck before plowing his 2009 Audi A4 sedan — which is registered to the New York Public Library — into another on East 138th Street around 3 p.m., according to sources and an eyewitness.

“I deeply regret embarrassment caused to my family and to The New York Public Library,” Marx said in a statement.

When cops hauled Marx out of the car, sources said he smelled of booze. More than an hour later, he allegedly blew a .19 on a blood alcohol test — more than twice the legal limit of .08.

“He just kinda came out of nowhere!” said sanitation worker Franklin Hernandez, who was sitting in his truck on 138th Street, between Madison and Fifth avenues, when Marx made his bizarre move.

“He was going pretty fast. He just missed the truck in front of me and then, bam! He smashed into my truck.”

“I jumped out, and he tried to put the car in drive — I just stood there in front of him, put my hand up and said, ‘Do not move that car!’ ”

Cops on duty at the race quickly responded.

“They told him to turn the car off, and he put his hands up,” Hernandez said. “One of the officers reached into his car, grabbed his keys and put them on the roof.”

Sources said Marx was trying to find a way around the marathon route where runners were coming off the Madison Avenue Bridge.

Before he was on 138th Street, he was spotted a few blocks away, trying to circumvent the route. “You could tell he was drunk,” Hernandez said.

Because of the race, Marx had to wait for cops to take him to the 28th Precinct station house, where he was given the blood alcohol test.

“He just sat there, for a good hour, in his car. Then they cuffed him and took him away,” Hernandez said.

He was charged with aggravated DWI and released without bail following his court appearance yesterday, sources said.