WASHINGTON - For every U.S. president, there comes a time to assume the role of the nation's comforter-in-chief, a leader who seeks to bring the country together and lift spirits in the midst of a national tragedy.

President Donald Trump found himself in that situation this week, consoling survivors of the worst mass shooting in recent U.S. history and traveling to Puerto Rico to comfort those devastated by Hurricane Maria.

The day after the tragedy in Las Vegas, Trump sounded a somber note at the White House: "May God give us the grace of healing and may God provide the grieving families with strength to carry on."

Later in the week, Trump traveled to Las Vegas, where he consoled the wounded and survivors and paid tribute to first responders who rushed to the scene.

도널드 트럼프 미국 대통령이 부인 멜
FILE - President Donald Trump and first lady Melania Trump walk with surgeon Dr. John Fildes at the University Medical Center after meeting with victims of the mass shooting in Las Vegas, Oct. 4, 2017.

"We stand together to help you carry your pain. You are not alone. We will never leave your side," he said.

Help for Puerto Rico

A day earlier, the president had been in Puerto Rico, pitching in on the relief effort and meeting with residents.

At several points during his visit, Trump seemed determined to push back at critics who complained that his administration had been slow to respond to the devastation wrought by Hurricane Maria.

WATCH: National Tragedies Thrust Trump Into Role of Comforter-in-chief

"Most of the hospitals are open, or at least partially open, but most of them now are open," Trump told residents. "And again, the job that has been done here is really nothing short of a miracle."

The Las Vegas massacre and the hurricane aftermath in Puerto Rico presented the president with a new and decidedly different test of his leadership qualities.

Big shoes to fill

Trump follows in the footsteps of past presidents who have taken on the role of national healer, including President Bill Clinton, who comforted survivors and those who lost family members in the bombing of the federal building in Oklahoma City in April 1995.

"You have lost too much, but you have not lost everything," Clinton said at a memorial service four days after the bombing. "And you certainly have not lost America, for we will stand with you for as many tomorrows as it takes."

In September 2001, it was up to President George W. Bush to both mourn and unify the country following the terrorist attacks of September 11. "We will rally the world to this cause by our efforts, by our courage. We will not tire, we will not falter and we will not fail," he told a joint session of Congress.

U.S. President Barack Obama speaks at a vigil held
FILE - U.S. President Barack Obama speaks at a vigil held at Newtown High School for families of victims of the Sandy Hook Elementary School shooting in Newtown, Connecticut, Dec. 16, 2012.

In December 2012, President Barack Obama sought to bring comfort and unity at a prayer vigil for the 26 mass shooting victims — 20 of whom were children — at Sandy Hook Elementary School in Newtown, Connecticut. "God has called them all home. For those of us who remain, let us find the strength to carry on and make our country worthy of their memory," he told members of the Newtown community two days after the attack.

In 2015, Obama also led a gathering in singing the Christian hymn Amazing Grace at a memorial service for the Reverend Clementa Pinckney, one of nine African-Americans killed by a racially motivated gunman at their church in Charleston, South Carolina.

Trump's challenge

Trump was elected president as an agent of political change. But in the wake of a national tragedy, analyst John Fortier said he now faces a different test.

"There will be more divisiveness when the [political] parties disagree about what to do about the aftermath in Las Vegas, but I think the president has played that role traditionally in Las Vegas," said Fortier, who is with the Bipartisan Policy Center in Washington.

President Donald Trump and first lady Melania Trum
FILE - President Donald Trump and first lady Melania Trump walk after arrival at the Luis Muniz Air National Guard Base in San Juan, Puerto Rico, Oct. 3, 2017.

He said Trump has demonstrated "less divisive moments" as president, particularly his deal with Democrats to put off a clash over the federal budget.

"Trump has assumed the traditional role, but it was marred a bit in Puerto Rico, with the controversy over the relief effort with local officials on the ground there. But the aftermath was broadly what we expect presidents to do. In Las Vegas, his role there has been more traditional," Fortier said.

Some of Trump's critics also seized on some of his comments during his visit to Puerto Rico, especially his eagerness to defend his administration's response to the relief demands there and criticism of Puerto Rico's precarious financial situation.

"Well, Puerto Rico, I thought, was typical Trump. It was about being divisive, not being a uniter," said Jim Kessler with Third Way, a center-left public policy research organization in Washington.

"I think he is more comfortable being in the dividing role. I think that he feels it helps him personally, it helps his political agenda. This is how he got elected," Kessler said.

Trump's duties as "comforter in chief" may last a bit longer, but his next major political challenge is getting his congressional agenda back on track, beginning with tax reform.

Both Kessler and Fortier are guests this weekend on VOA's "Encounter" program.