President Obama spoke in rememberance of the three victims of the Boston Marathon bombing and praised the resilience of the city of Boston at an interfaith service on Thursday. (The Washington Post)

President Obama spoke to Boston and the nation Thursday about resilience and perseverance, but his words could easily apply to his own emotional state amid perhaps the most difficult week of his second term.

A president often accused of not feeling the nation’s pain has drawn on emotion this week to describe a broad defeat of gun-control legislation and to help heal a city after the bombing attack on the Boston Marathon.

Those setbacks — one for the country’s sense of security and another for the president’s second-term agenda — have revealed a different Obama.

During his first term, Obama was often clinical when it came to policy decisions and his public message, sometimes to the disappointment of his more ideological base. But this week, he has expressed exasperation, anger and sorrow in responding to a political defeat in Washington and to national adversity in the Boston attacks.

“We may be momentarily knocked off our feet, but we’ll pick ourselves up,” Obama told those gathered at the Cathedral of the Holy Cross, citing the example of Bill Iffrig, 78, a runner who was blown down from a bomb blast as he approached the finish line. “We’ll keep going. We’ll finish the race.”

As he took his place in a front-row pew, Obama wiped tears from his eyes amid swelling applause.

The moment recalled the last time he wept publicly — on the mid-December day when a gunman opened fire inside Sandy Hook Elementary School in Newtown, Conn., killing 20 children and six women.

Obama pledged then to seek tighter restrictions on gun sales, and he made the Newtown families the face of his effort. It is the technique of the community organizer he once was.

But his national campaign for gun control was defeated Wednesday when the Senate, controlled by his party, blocked the core of his legislative plans, including the publicly popular proposal to expand background checks for firearm sales.

In the aftermath, Obama, using a word loaded with opprobrium, said, “All in all, this was a pretty shameful day in Washington.”

“I’ve heard some folks say that having the families of victims lobby for this legislation was somehow misplaced,” he continued, surrounded by Newtown parents and former congresswoman Gabrielle Giffords (D-Ariz.), who was severely injured in a shooting in 2011. “ ‘A prop,’ somebody called them. ‘Emotional blackmail,’ some outlet said. Are they serious?”

This was an Obama unrecognizable from his first term, when he spoke about bending “cost curves” in pushing for universal health care and about contract law when corporate executives were receiving generous bonuses amid economic despair.

But his angry analysis, while stirring to supporters, could not hide his inability to rally enough senators behind hugely popular gun measures.

A senior administration official said Obama thinks the Senate’s defeat of gun legislation was the result of “rank cynicism and cowardice” — a “dichotomy,” the official said, “given the bravery we all saw in Boston a few days earlier.”

“He knew this would be very hard, and no one advised him not to do it, because to do nothing would have been such a failure of leadership,” said the official, who spoke on the condition of anonymity to discuss White House thinking about the setback. “I think our supporters would have revolted, and they should have if we had done nothing.”

Of his legislative priorities, gun control was not one whose public support was validated by his last election.

The Newtown massacre happened after Election Day, and Obama made gun control a priority in his second inaugural address, his State of the Union speech and visits to a cities that have suffered gun violence in recent months.

That was not enough, as he realized this week. A president’s moral outrage bumped up against the lobbying clout of the National Rifle Association and a challenging midterm election map for some Democratic senators.

“It was a massive reach, really,” said Stephen Hess, a presidential scholar at the Brookings Institution.

It has taken years in the past for presidents, including Bill Clinton, to secure gun-control measures, and Hess said the political dynamic in Washington has largely remained unchanged.

Obama and his advisers said repeatedly that securing what they had proposed would not be easy. But as bipartisan compromise emerged over the amendment to expand background checks, there was more fear of the Republican-controlled House than of a Democratic-run Senate that appeared ready to act.

“I think it’s fair to chalk it up as an honorable, decent fight that told us a lot about the man who had never shown this sort of emotional response before,” Hess said. “Now you move on.”

Obama moved on Thursday to Boston, where the first large-scale attacks on U.S. soil in the post-Sept. 11, 2001, era were carried out on a holiday afternoon this week.

He invoked his history in celebrating Boston’s, noting his time in the city during law school at Harvard and as the site of a speech he made at the 2004 Democratic National Convention that launched his national political career.

His remarks then were built around the notion of ending the partisanship that gripped Washington. His comments Thursday were far different.

“This is personal,” he said. “This is personal.”

Obama used the victims of Newtown to tell a story of tragedy and redemption for families, a city and the country. He quoted Scripture to start, urging those gathered to “run with endurance the race that is before us.”

“That’s what you’ve reminded us — to push on,” Obama said. “We finish the race.”

He has told the Newtown families and the nation that he intends to do so with gun control, even as immigration legislation takes shape and negotiations over the federal budget begin.

Said the senior administration official: “The backlash may be felt in the 2014 election, it may be felt in the 2016 elections, but the political landscape will be different in the future for those who opposed this. By having this fight, we’ve made it more likely that something will get done the next time.”

Discuss this topic and other political issues in the politics discussion forums.