Theresa May said the diplomats, who have a week to leave, were identified as "undeclared intelligence officers".
The UK later told the UN Security Council that Russia had used "a weapon so horrific that it is banned in war" in a "peaceful" British city.
Russia denies attempted murder and says it will respond appropriately.
Mrs May also revoked an invitation to Russia's foreign minister, and said the Royal Family would not attend the Fifa World Cup in Russia later this year.
Addressing the UN Security Council, Britain's deputy UN ambassador, Jonathan Allen, accused Russia of breaking its obligations under the Convention on the Prohibition of Chemical Weapons.
He said he had heard the threats from Russia but that the UK would not be deterred.
"We will stand by the values which are shared by the overwhelming majority of those in this council in this United Nations and we ask you today, to stand by us," he added.
In response the Russian ambassador to the UN, Vasily Nebenzya, denied Moscow's involvement in the attack and demanded "material proof" from Britain to support its charge.
He said: "We were given an ultimatum and requested in 24 hours to admit that we committed a crime. In other words, confess.
"We do not speak the language of ultimatums. We do not use that language with anyone. And we will not allow to be spoken to in that language either."
Mr Allen said the UK government has asked the Organisation for the Prohibition of Chemical Weapons, an independent watchdog, to verify its identification of the substance used in Salisbury.
The US ambassador Nikki Haley said Washington stood in "absolute solidarity" with Britain, citing the "special relationship" between the two countries and saying the US would "always be there" for the UK.
The mass expulsion is the largest since 31 were ordered out in 1985 after double agent Oleg Gordievsky defected.
Former spy Sergei Skripal, 66, and his daughter, Yulia Skripal, 33, remain critically ill in hospital after being found slumped on a bench on 4 March.
Det Sgt Nick Bailey fell ill while responding to the incident, and is in a serious but stable condition, but is thought to be improving.
Moscow refused to meet Mrs May's midnight deadline to co-operate in the case, prompting Mrs May to announce a series of measures intended to send a "clear message" to Russia.
- Expelling 23 diplomats
- Increasing checks on private flights, customs and freight
- Freezing Russian state assets where there is evidence they may be used to threaten the life or property of UK nationals or residents
- Ministers and the Royal Family boycotting the Fifa World Cup in Russia later this year
- Suspending all planned high-level bilateral contacts between the UK and Russia
- Plans to consider new laws to increase defences against "hostile state activity"
Mrs May told MPs that Russia had provided "no explanation" as to how the nerve agent came to be used in the UK, describing Moscow's response as one of "sarcasm, contempt and defiance".
The use of a Russian-made nerve agent on UK soil amounted to the "unlawful use of force", she said.