President Barack Obama worked through an unruly crowd Sunday in Bridgeport to excite the Democratic faithful to turn out for Gov. Dannel P. Malloy in Tuesday’s nail-biter of a gubernatorial election.

Malloy, a first-term Democrat, is facing Republican Tom Foley, a Greenwich businessman who he beat by less than half a percentage point in 2010. The two men are still in a dead heat today, according to most public opinion polls.

Obama, who also stumped for Malloy just before the 2010 election, delivered a 20-minute speech to a rowdy audience of more than 1,900 people packed into Bridgeport Central High School’s gymnasium.

Hugh McQuaid photo

The president tried to draw contrasts between the two candidates. He said the learning and physical disabilities that Malloy struggled with throughout his life have helped to shape his politics.

“And Dan, this is personal for him. We were talking on the helicopter ride over, it was a little windy, but Dan was talking about what it meant growing up with a learning disability,” he said. “You don’t lose that sense of being the underdog. You don’t lose that sense of somebody else giving you a hand up. That’s what his politics are based on.”

However, the president was repeatedly interrupted by immigration activists who were scattered throughout the audience and began shouting at different times during his speech. The rest of crowd responded to each interruption by booing and chanting “Four more years.” Obama called the crowd “rowdy,” but took the interruptions in stride.

Hugh McQuaid photo

“I just want to say, because we’ve now had like three folks, I am sympathetic to those who are concerned about immigration. The truth of the matter is that we’re a country of immigrants. That’s why we fought for immigration reform. It’s the other party that’s blocked it,” he said.

First Lady Michelle Obama was also heckled by immigration activists last week during her visit to a New Haven school.

After each interruption Obama moved back to stressing the importance of voting on Tuesday. He called Republicans “patriots” who loved their country. Someone in the crowd loudly disagreed.

“But listen,” Obama said, “just because folks are good folks, doesn’t mean they’ve got good ideas . . . I’ve got some family members who I love, but they’ve got bad ideas. So I don’t want them in charge of anything. Some of them will be over for Thanksgiving.”

The president pointed to Malloy’s tight margin of victory in 2010 and said voters should not “let somebody else choose your future for you.”

“Four years ago, Dan won the governor’s race by just four per precinct. Four votes,” he said. “. . . Your vote matters, don’t let people tell you it doesn’t. On Tuesday, your vote will determine the course for Connecticut. So, we need your vote and more importantly the vote of your friends, your neighbors, your colleagues.”

Hugh McQuaid photo

On Friday, Malloy said Obama’s visit, as well as an appearance last week by First Lady Michelle Obama, would “generate a lot of excitement” among Democrats.

But Foley said he did not expect Obama’s visit to have a major impact on Tuesday’s election.

“I think it’s great the President of the United States is coming here, but I don’t think that it’s going to affect how people vote in Connecticut on Tuesday because it doesn’t really have anything to do with Connecticut’s future and their future,” Foley said Sunday after the WTNH debate.

The governor also said he was confident in his campaign’s get-out-the-vote strategy, calling it “superior to anything we’ve ever had in this state before.”

In addition to the Obamas, Malloy has twice hosted former President Bill Clinton as well as Puerto Rico Gov. Alejandro García Padilla.

Foley’s surrogate strategy has largely centered on New Jersey Gov. Chris Christie, head of the Republican Governors Association and a potential presidential candidate in 2016. Christie has stumped for Foley several times in the last few weeks and will appear with him again Monday in Windsor Locks. On Saturday, Foley also received support from former Puerto Rico Gov. Luis Fortuño.