Midterm elections are just over two weeks away, yet President Obama held his first campaign rally on behalf of a specific candidate when he traveled just outside Washington, D.C., to help boost support for Maryland's Democratic gubernatorial candidate, Anthony Brown.

Brown, the current lieutenant governor, is locked in a surprisingly tight race against Republican Larry Hogan despite the state's strong Democratic tilt. Brown has stumbled in recent weeks defending his role in the state's botched health care rollout, and his team sought the White House's help in the closing weeks.

"Anthony Brown has not just devoted his career to fighting for you; he's devoted his entire life to fighting for you. And that's what this election's all about: who is going to fight for you," Mr. Obama said.

Get Breaking News Delivered to Your Inbox

Though it was his first official midterm campaign rally, much of the president's material was promoting the Democratic agenda that he has talked about all year: raising the minimum wage, ensuring equal pay for women and expanding health care coverage through the Affordable Care Act.

He said that while Republicans are "patriots" who love their country and family, they will only help those already at the top of the economic ladder.

"You know who they're fighting for and it ain't you," the president said.

At one point he was interrupted by a heckler who appeared to be protesting against deportations of immigrants in the U.S. illegally. Though the crowd sought to drown out the protester with boos, Mr. Obama addressed the issue

"I'm actually for immigration reform, and the reason we haven't done immigration reform is because Congress, congressional Republicans in the House of Representatives have been blocking immigration reform," the president said. "Of course you should be protesting the folks who are blocking it, but that's okay."

He also urged voters to reject the "cynicism" he says Republicans are peddling in an effort to keep voters home.

"Cynicism is a choice and hope is a better choice," Mr. Obama said. "We're selling hope. That's what Anthony Brown's about."

Though attendees had waited hours to attend the rally, many began streaming out just after Mr. Obama began speaking.

The president has been active on the Democratic fundraising circuit but has avoided the campaign trail to avoid dragging down Democrats who might be hampered by his low approval rating. Aides have said he will ramp up his campaign efforts in the final days before the election, mostly to improve turnout among the groups like young people and minorities who were crucial to his 2008 and 2012 victories but tend to stay home in far greater numbers in midterm years.

His first event was supposed to be a rally for Connecticut Gov. Dannel Malloy last week, but Mr. Obama canceled at the last minute to focus on the Ebola crisis.

After the rally in Maryland Sunday, Mr. Obama heads to Chicago for a rally with Illinois Gov. Pat Quinn, another Democrat who is maintaining only a slim lead over Republican Bruce Rauner.