Prime Minister Theresa May praised the "tremendous" work of the military as she visited Liverpool to mark Armed Forces Day.
Mrs May joined the Earl of Wessex, representing the Queen, and Defence Secretary Sir Michael Fallon for the national event on the city's waterfront.
She said: "It is wonderful that we mark the tremendous job that our armed forces do for us here at home and across the world, helping to keep us safe.
"Of course recently, after the terrible terrorist attack in Manchester, we saw our armed forces on the streets helping to reassure people of their safety and security, and it's great that we recognise the work that all our armed forces do, as I say, both here and across the world.
"They do a fantastic job for us and we should be grateful to them all."
Sir Michael also praised the reaction of the Army following the Manchester Arena bombing, in which 22 people were killed.
He said: "The armed forces are always ready now to deploy in aid of the police, as back-up for the armed police and in aid of local authorities.
"The operation after Manchester has been well-rehearsed. They were ready to deploy.
"We deployed nearly 1,000 armed troops within 12 hours on the streets, which freed up armed police to do more patrolling."
He paid tribute to the work done by service personnel across the world.
He said: "There are some 10,000 servicemen and women who are working for us around the globe on operations or in our bases.
"They have been helping to deal with Daesh terrorism, they have been helping to rescue migrants in the Mediterranean, they have been on Nato deployments, they have been peacekeeping in South Sudan.
"All of that keeps us safer here at home."
Mrs May, who attended the event with husband Philip, toured some of the displays at the event with Mayor of Liverpool Joe Anderson.
She stopped to pose for pictures with some of the hundreds who attended the celebration on Liverpool's Pier Head and was cheered by many in the crowd, although some booing was also heard.
Military personnel, their families and veterans gathered in the city for the ninth annual Armed Forces Day.
The event began with a gun salute and parade and also included receptions, displays, a visit from Royal Navy ship HMS Iron Duke and flypasts by the Red Arrows and Typhoon.
More than 300 other events will take place around the world as part of the celebrations.