An out-of-control city bus clipped a traffic agent in Midtown yesterday evening before careening onto a sidewalk and slamming into an office building, injuring dozens of passengers.

The lumbering M34 bus was heading east on 34th Street between Eighth and Ninth avenues just after 7 p.m. when it veered into the opposite lanes and jumped the curb, police said.

The bus plowed over several trees before crashing to a halt.

“This may be a true miracle on 34th Street, that you could have a city bus go up on the sidewalk at 7 o’clock on a warm summer night and have only one person get hit,” said Richard Scheirer, the city’s director of emergency management.

The 25-year-old driver and the traffic agent were among the injured. Both were in stable condition at area hospitals.

The 32 passengers suffered minor injuries, authorities said.

“I heard a lot of screaming and yelling, I saw people falling on each other inside the bus,” said security guard Orlando Ibanez, who was working across the street.

Passenger David Gadayer was not seriously hurt but said he may never ride a bus again.

“Right now I’m too scared, and I’m in pain,” winced Gadayer as he gingerly moved toward a waiting ambulance.

“I’m very shaken, and very scared to ever get on another bus again,” said the 26-year-old salesman from Queens. “The driver just lost control, he started hitting trees.”

Inspectors from the Buildings Department will examine the building hit by the bus to make sure it suffered no structural damage, officials said.