Boris Johnson has hailed Nato as "the most successful alliance in history" after talks with leaders near London.
The PM insisted there was "very great solidarity" within the alliance, amid tensions on its 70th anniversary.
He also praised the role of the United States, adding the country had been a "pillar of stability" on security issues.
Jeremy Corbyn said he wanted to ensure Nato focused on reducing "tensions around the world".
Leaders of the 29-member military alliance have been discussing shared security issues at a special meeting to mark 70 years since its formation.
In a statement issued after talks at a luxury resort near Watford, leaders acknowledged the "challenges" posed by China and Russia, and pledged to take "stronger action" against terrorism.
On Tuesday, Nato Secretary General Jens Stoltenberg said countries in the alliance had added $130bn (£100bn) to defence budgets since 2016, and that this number would increase to $400bn by 2024.
US President Donald Trump has frequently criticised how much other allies spend on defence.
Speaking to reporters at a press conference afterwards, Mr Johnson said member countries were making "real progress" towards meeting a target to spend 2% or more of their economic output on defence.
Asked whether President Trump was good for the UK, the prime minister said the US had always "should shoulder to shoulder" with the country.
He added that the country's response after the Salisbury poisonings last year had been a "fantastic testament to the transatlantic alliance".
'Changed its focus'
Pressed directly to comment on Mr Trump as a leader, Mr Johnson said the administration he leads "could not have been more supportive".
Labour leader Jeremy Corbyn said his party was committed to remaining part of the Nato alliance, adding it was "important to be part of".
"I think we'll have to contribute to world peace through Nato and any other alliance, principally through the United Nations," he added.
Although Labour's manifesto pledges to maintain the UK's commitment to Nato, Mr Johnson accused Labour of wanting to "destroy" it.
Mr Corbyn has previously attacked the organisation "as a danger to peace", but on Wednesday said: "We have decided we'll remain in Nato as a party, and that's it."
He added that he thought Nato was going in the "wrong" direction back in 2011, but the alliance has since "changed its focus".
On Tuesday evening, leaders attended receptions at Downing Street and at Buckingham Palace.
The prime minister held talks with German Chancellor Angela Merkel, French President Emmanuel Macron and Turkish President Recep Tayyip Erdogan to discuss Syria, Libya and counter-terrorism at No 10.
He had faced questions over whether he was avoiding a one-to-one meeting with Mr Trump, over concerns it could blow his election campaign off course, but Downing Street said the two men had a low-key, off camera meeting.
On Wednesday, Mr Johnson said he had not talked about the NHS during the meeting, but did talk about "all manner of areas of cooperation, from Nato to Syria to trade".
Labour has claimed throughout the election campaign that the future of the health service could be threatened by a post-Brexit trade deal with the US.
Later in the evening, Mr Johnson was filmed chatting with a group of leaders during a reception at Buckingham Palace - they appeared to be discussing the US president.
Mr Johnson said it was "complete nonsense" to suggest he did not take Donald Trump seriously after the video emerged.
President Trump has cancelled a planned press conference, telling reporters: "We'll go directly back. I think we've done plenty of news conferences."
Labour leader Jeremy Corbyn - who said he intended to ask the US president for "reassurances" that the NHS would be "off the table" in post-Brexit trade talks - was also at the reception, but says he did not have an opportunity to speak to him.
Speaking at a press conference earlier in the day, Mr Trump had said he wanted "absolutely nothing to do with" the NHS, adding he would not touch it even if it was handed to his administration "on a silver platter".
Asked whether he could work with Mr Corbyn as prime minister, he said he could "work with anybody", although earlier he said he thought Mr Johnson would do a "good job".