Both sides released comments saying that the U.S. and Pakistan want to continue to work together and that Islamabad plays a key role in the struggle for peace in Afghanistan.
In brief comments before their meeting, Pakistan Prime Minister Shahid Khaqan Abbasi said his country is committed to the war on terror and shares the same common objectives as the U.S.
"Engagement is there," he said, adding that they "need to move forward with (the) issues at hand."
Mattis did not speak while reporters were present. A Pentagon statement said that during the meetings Mattis discussed Pakistan's role in the peace process and "reiterated that Pakistan must redouble its efforts to confront militants and terrorists operating within the country."
A senior U.S. official said the meetings were "straightforward," and that Mattis was very specific about what Pakistan needs to do to show it is taking action against the militants. Asked if Mattis set any timelines, the official said the urgency of the matter was communicated.
The official, who spoke on condition of anonymity to discuss private meetings, said Mattis also made it clear that Pakistan must do its part to bring the Taliban to the negotiating table with Afghanistan.
A statement from Abbasi's office said the prime minister talked about recent counterterrorism operations and said Pakistan "would continue to conduct intelligence based operations all over the country." And it said Abbasi appreciates "the U.S. resolve not to allow the use of Afghan soil against Pakistan."
Earlier, Mattis told reporters traveling with him that he wants to work with Pakistan to address the problems, adding that the U.S. is committed to a pragmatic relationship that expands cooperation while also "reinforcing President Trump's call for action against terrorist safe havens."
"We have heard from Pakistan leaders that they do not support terrorism. So I expect to see that sort of action reflected in their policies," Mattis said before his trip to Islamabad.
Mattis met with Abbasi and army chief Gen. Qamar Javed Bajwa, as well as a number of senior Pakistani leaders and military officials and U.S. Ambassador David Hale. It was Mattis' first trip to Pakistan as secretary.
Bajwa, in a statement, said Mattis expressed concern about militants in Pakistan trying to "further their terrorist agenda" in Afghanistan, and said he is "prepared to look into the possibility of miscreants exploiting Pakistan's hospitality."
Mattis' statement reflects persistent U.S. assertions that Islamabad is still not doing enough to battle the Taliban and allied Haqqani network insurgents within its borders.
Since the start of the war in Afghanistan, militants in Pakistan have crossed the mountainous and ill-defined border to wage attacks, then return to safe havens in Pakistan, where they have had a long-standing relationship with the ISI, Islamabad's intelligence agency.
In a blunt assessment early last week, Gen. John Nicholson, the top U.S. commander in Afghanistan, said there have been no changes in Pakistan's support for militant networks.
He said Pakistani leaders went to Kabul and met with Afghan President Ashraf Ghani.
"They identified certain steps that they were going to take. We've not yet seen those steps play out," Nicholson told reporters in a recent briefing.
The U.S., he said, has been very direct about what it expects Pakistan to do in the fight against the Taliban.
"We're hoping to see those changes," he said.
Following Mattis' visit, Pakistan's prime minister's office released a statement saying there are no safe heavens in Pakistan and that the nation was committed to eradicating terrorism once and for all.
In August, the United States said it would hold up $255 million in military assistance for Pakistan until it cracks down on extremists threatening Afghanistan.
Imtiaz Gul, an Islamabad security analyst, said U.S. officials always come to Islamabad with their "own wish list."
"I am sure the U.S. defense secretary is also carrying a wish list with him but I don't think Pakistan will accept any dictation as it has already demonstrated its seriousness in fighting terrorism, and Washington in recent weeks has appreciated and acknowledged Pakistan's sacrifices in war on terror," he said.
Gul said relations between Pakistan and the U.S. have gone from bad to worse since the Trump administration announced Afghan strategy in which Pakistan was degraded and India was elevated.
President Donald Trump's tough words about Pakistan as he unveiled the updated U.S. strategy for the war in Afghanistan, infuriated Islamabad and triggered anti-U.S. protests there that Pakistani police had to use tear gas to disperse
Mattis' trip to Pakistan comes at the end of a short trip to the region, including stops in Egypt, Jordan and Kuwait.
Associated Press writer Ahmed Munir contributed to this story from Islamabad
Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.