Boris Johnson said he is "deeply troubled" by failures to properly commemorate black and Asian troops who died fighting for the British Empire during World War One.
Some troops were commemorated collectively or their names were recorded in registers, while their white counterparts had headstones.
Defence Secretary Ben Wallace apologised in the Commons after a report blamed "pervasive racism".
Mr Wallace pledged to "take action".
The prime minister offered an "unreserved apology" over the findings of the review by the Commonwealth War Graves Commission.
"Our shared duty is to honour and remember all those, wherever they lived and whatever their background, who laid down their lives for our freedoms at the moment of greatest peril," he said.
Mr Wallace expressed "deep regret" in the House of Commons, as he told MPs there was "no doubt" prejudice had played a part in what happened after WWI.
The Commonwealth War Graves Commission, which is tasked with commemorating those who died in the two world wars, has also apologised over its findings.
Labour MP David Lammy, who was critical to bringing the matter to light, called it a "watershed moment".
Mr Wallace said: "On behalf of the Commonwealth War Graves Commission and the government both of the time and today, I want to apologise for the failures to live up to their founding principles all those years ago and express deep regret that it has taken so long to rectify the situation.
"Whilst we can't change the past, we can make amends and take action," he said.
He said there were cases where the commission "deliberately overlooked evidence" that would have allowed it to find the names of the dead.
And he said there were examples of officials employing an "overarching imperial ideology connected to racial and religious differences" in order to "divide the dead and treat them unequally in ways that were impossible in Europe".
Outlining the next steps, Mr Wallace said the Commonwealth War Graves Commission will:
- search in the historical record for inequalities in commemoration and act on what is found
- renew its commitment to equality in commemoration by building physical or digital commemorative structures
- use its online presence and wider education activities to reach out to all the communities of the former British Empire touched by the two world wars to make sure their hidden history is brought to life
- and, over the next six months, assemble a global and diverse community of experts to help make this happen
Mr Wallace also announced a public consultation over plans to waive the visa fee for service personnel from the Commonwealth and Nepal who choose to settle in the UK in order to honour their contribution.
An inquiry by the commission was set up following a 2019 Channel 4 documentary, called Unremembered, which was presented by Mr Lammy.
The report found that at least 116,000 casualties from WW1, most of whom were of African, Indian or Egyptian origin, "were not commemorated by name or possibly not commemorated at all".
But that figure could be as high as 350,000, it said.
It also cited racist comments such as the governor of a British colony saying in 1923 that: "The average native... would not understand or appreciate a headstone."
Shadow justice secretary Mr Lammy told the BBC that while making the documentary in Kenya and Tanzania, he discovered mass graves in which Africans had been "dumped with no commemoration whatsoever".
He said it was a travesty that men who served the British Empire were not commemorated properly, but welcomed the report.
"I'm just really, really pleased that the dignity that these men deserved - who were dragged from their villages and commandeered to work for the British Empire - that dignity that they deserve in death can be granted to them," he said.
Mr Lammy added that work must be done to find their names in archives where that is possible, and to establish how local communities would like them to be commemorated.
He also said Commonwealth soldiers should not be "whitewashed" out of history books, while Mr Wallace said it was a "deep regret" that his own WW1 education had included "very little about the contribution from the Commonwealth countries and the wider at the time British Empire".
Historian Prof David Olusoga, whose TV company produced Unremembered, told BBC Breakfast that apologies were not enough and resources would need to be committed if the commission was serious about restorative justice.
"If the Commonwealth War Graves Commission had set up a committee and discovered that 100,000 white British soldiers lay in mass graves - unmarked, uncommemorated - and the documentation proved that that had been deliberate, what would they do?" he said.
Six million soldiers from the British Empire served in WW1.
Between 45,000 and 54,000 Asian and African personnel who died in the conflict were "commemorated unequally", the commission said.
What was the role of British Empire soldiers in WW1?
- World War One was the first truly global war, fought not just in the trenches of France but in the Middle East, Asia and Africa
- Britain's colonies sent millions of men to fight for the empire during the conflict
- India, which at that time included Pakistan and Bangladesh, sent the most soldiers - more than 1.4 million
- The British Army in East Africa was mainly composed of African soldiers by November 1918, according to the Imperial War Museum
- At least 180,000 Africans served in the Carrier Corps in East Africa and provided logistic support to troops at the front
- Around 15,000 people from the West Indies enlisted in WW1, including 10,000 from Jamaica, according to the National Army Museum
- Colonies as far away as Canada, Australia, New Zealand, South Africa and Rhodesia (now Zimbabwe) also sent a similar number between them
- Britain had soldiers from six different continents: Europe, North America, South America, Australasia, Asia and Africa
The report concluded that the failure to properly commemorate the individuals was influenced by a scarcity of information, errors inherited from other organisations and the opinions of colonial administrators.
"Underpinning all these decisions, however, were the entrenched prejudices, preconceptions and pervasive racism of contemporary imperial attitudes," it added.
The report picked out an example from 1923 when the governor of the Gold Coast colony, now Ghana, argued for collective memorials rather than individual ones.
At a meeting in London, it was said that the governor, F G Guggisberg, said: "The average native of the Gold Coast would not understand or appreciate a headstone."
In response, commission employee Arthur Browne said: "In perhaps two or three hundred years' time, when the native population had reached a higher stage of civilisation, they might then be glad to see that headstones had been erected on the native graves and that the native soldiers had received precisely the same treatment as their white comrades."
The report said Mr Browne's response showed "what he may have considered foresight, but one that was explicitly framed by contemporary racial prejudice".
The commission, which was founded in 1917 as the Imperial War Graves Commission, said the events of a century ago were wrong then and were wrong now.
Its director general, Claire Horton, said: "We recognise the wrongs of the past and are deeply sorry and will be acting immediately to correct them."
As part of the commission's work to search for unnamed war dead and those who are potentially not commemorated, it will also look at those who died in World War Two, although it is not thought that inequalities seen in WW1 were as widespread then.
Ms Horton said the report was "sober" reading but gave the commission the ability - "now that we know the numbers and the areas to look" - to start the searches properly to "right the wrongs of the past".
The war graves commission was founded with a remit to remember every individual who had died in World War One, regardless of rank, class, religion or race.
The idea of equal treatment was controversial, but it became a cornerstone of remembrance.
Outside Europe, however, the commission enacted a policy of extreme discrimination, categorising the fallen as "white", "Indians" or what it called "natives".
In southern Kenya, white soldiers lie beneath named memorials in a well-tended cemetery. Next door in a scruffy field is where their African comrades are buried - no names, just a general memorial.
The consequence of the commission's failings is not only to do a great injustice to the black and Asian soldiers, sailors and airmen who fought alongside their white European comrades in two world wars, it is to misrepresent our history.
Do you have a relative who was not properly commemorated? Please share your story by emailing firstname.lastname@example.org.
Please include a contact number if you are willing to speak to a BBC journalist. You can also get in touch in the following ways:
- A YEAR TO CHANGE THE WORLD: 'I don't want you to listen to me, I want you to listen to the science'
- FOUR JOBS THAT CAN SAVE THE WORLD: Careers that are reducing our impact on the planet