Police Officer Wayne Rhatigan, the mounted patrol cop who first investigated the smoking Nissan Pathfinder at around 6:30 p.m. last night. (SETh GOTTFRIED)

A car bomb nearly caused a bloodbath in the heart of Times Square yesterday as a homemade explosive device in an SUV parked outside the doors of “The Lion King” fizzled out.

The bomb caused a terror scare that forced thousands of people to evacuate the Crossroads of the World and turned Times Square into a ghost town for hours.

An unidentified T-shirt vendor, who is a Vietnam veteran, saw smoke billowing from a Nissan Pathfinder and alerted Police Officer Wayne Rhatigan, a mounted patrol cop, who looked inside the smoldering vehicle at around 6:30 p.m. on West 45th Street near Seventh Avenue in front of an entrance to the Minskoff Theatre, which houses the hugely popular Disney musical, Mayor Bloomberg said early this morning.

Rhatigan, who has been on the force for 19 years, the last four in the Mounted Unit, smelled gunpowder and called in the Fire Department, which put out the car fire as he and two patrol officers cleared the area of civilians.

Bomb Squad members then searched the SUV, which bore Connecticut license plates that were actually registered to a Ford F-150, and found two gasoline cans, three propane tanks, electrical wires, black powder, consumer grade fireworks and two clocks, Police Commissioner Ray Kelly said.

“I think the intent was to cause a significant ball of fire,” Kelly said.

A Bomb Squad robot was used to handle the suspicious package in the back of the vehicle, officials said.

Bloomberg called the device “amateurish” but said that the city was “very lucky” because of the quick-thinking actions of the hero T-shirt vendor and Rhatigan.

There was a “box within a box” in the car, a 2X2X4 black gun locker, Kelly said.

Officials dismantled the first device and were in the process of rendering the second box safe this morning at the department’s firing range in the Bronx.

An NYPD security camera caught the Pathfinder travelling west on West 45th Street at 6:28 p.m. and at 6:34 p.m. the 911 call came in, Kelly said.

The Mayor added that the cameras, “couldn’t detect who was in the vehicle, how many were in the vehicle and what was in the vehicle.”

Cops were looking at other security videos from various cameras in the area that may have captured images of the suspect.

Authorities searched the immediate area for any possible secondary devices, but no other areas were evacuated. Also an NYPD and federal manhunt for the suspect began.

Investigators interviewed the person who had the license plates before they were put on the Pathfinder. That person is not a suspect and told officials that he dropped the plates off at a junkyard. Police are trying to track down the owner of that junkyard.

“It looked like something digital. It went off, it just didn’t go off like it was intended to,” a law-enforcement source told The Post.

Bloomberg and Ray Kelly were in Washington last night for the White House Correspondents Dinner and immediately rushed back to the city. President Obama was alerted and monitoring the situation.

“The president commended the quick action by the NYPD and…the federal government is prepared to provide support,” Obama spokesman Nick Shapiro said in a statement.

Witnesses earlier said they saw a man running from the SUV but Bloomberg denied this at the early morning press conference. The vehicle was parked at such an angle that investigators believed the driver had pulled over in a hurry, sources said.

The improvised explosive device certainly could have claimed many lives if it hadn’t failed, sources said.

“It definitely was going to be a substantial fire and explosion,” a source said.

“Anybody in the immediate area could have been killed.”

Witnesses described the chaotic scene seconds after smoke started coming from the vehicle.

“Within seconds police were here pushing everyone out of the building and away from the center of Times Square,” said Okan Yildiz, 25, who works at the nearby Sunglasses Hut.

“Everybody was running for their lives, they were totally afraid. I saw everybody streaming from out of the building,” he said. “I thought the terrorists finally got to Times Square.”

Another panicked witness thought she was going to die.

“I was so scared, I almost forgot how to use my legs,” said Chrystal Gottsechalk.

“I kept tripping and falling down, I didn’t think I was going to make it,” she said.

Fire Department personnel heard what “sounded like fireworks” going off, and the NYPD Bomb Squad and Emergency Service Unit were on the scene, along with FBI agents from the Joint Terrorist Task Force, sources said.

“It just looked like more than a typical car fire,” a source said.

Several staffers in the Minskoff told The Post they heard an explosion. It was unclear if that noise was from the bomb or from the NYPD robot breaking into the car.

The disturbing find led cops to close West 43rd to West 48th streets between Sixth and Eighth avenues, and West 45th Street between Seventh and Eighth avenues.

The subway system wasn’t affected, however, according to an NYC Transit spokesman.

Also, the car was parked close to the headquarters of Viacom, which owns the Comedy Central cable network.

Comedy Central aired a recent controversial episode of the animated “South Park,” depicting the prophet Mohammed in a bear costume, drawing the ire of some extremists.

“The Lion King” performance was canceled but other shows went on with barely half of their usual Saturday night audience.

“We were going to see ‘The Lion King’ but the streets were closed,” said Long Islander Rich Gaudino, who had paid a total of $4,000 for tickets for him, his wife and two daughters.

“The police weren’t sharing information about what was going on or how long it would take. It’s really frustrating not to know what’s going on.”

Nearby hotels were evacuated, forcing countless tourists to wait in the street in the middle of the night. Major businesses such as the Toy ‘R’ Us and McDonald’s in Times Square were evacuated and closed all last night.

Brandi Kantari, from San Diego, said, “This really sucks, but the NYPD doesn’t want to take any chances.

“The tourists are the ones who are mad, and the New Yorkers are the ones who just seem to be going around and not bothered by it,” said Kantari, who missed her performance of “Mary Poppins.”