President Jean-Claude Juncker interviewed King as the candidate to replace former Commissioner Jonathan Hill last month.
Hill had headed the financial stability, financial services and the capital markets union portfolio until resigning after the Brexit vote.
On Tuesday, a Commission source said, "The Commissioner for the security union will support the implementation of the European agenda on security that the European Commission adopted on 28 April 2015. He will contribute to delivering an operational and effective security union."
King, he said, will work under the guidance of First Vice-President Frans Timmermans, in charge of better regulation, interinstitutional relations, the rule of law and the charter of fundamental rights and support and complement the work of Dimitris Avramopoulos, the Commissioner for migration, home affairs and citizenship.
A task force composed of experts from several Directorates-General and supervised by the Director-General for home affairs will support the Commissioner for security union. As this is a new portfolio that complements existing portfolios, the responsibilities of the other Commissioners remain untouched.
On the choice of the portfolio, Juncker consulted Martin Schulz, the President of the European Parliament, as well as several other leading MEPs. He also informed UK Prime Minister Theresa May of his choice on Monday.
Juncker also wrote to Robert Fico, Prime Minister of the Slovak Republic, currently holding the rotating presidency of the Council of the EU.
King will have an exchange of views on his new role with the European Parliament after the summer recess.
A Commission spokesperson said, "In spite of the referendum in the UK of 23 June where a majority voted for the UK to leave the EU, Britain is still a member of the EU and thus entitled to a Commissioner."
The decision was welcomed by Conservative home affairs spokesperson Timothy Kirkhope.
The MEP said the appointment reflected the UK's continuing leadership role in security issues, which recently saw the Yorkshire and the Humber MEP pilot the landmark passenger name record directive through the European Parliament. In addition, a Briton, Rob Wainwright, is currently Director of Europol.
"We face a global terrorist threat and this announcement sends a strong signal that the security relationship between Britain and the EU will remain of key importance post-Brexit," said Kirkhope.
"Sir Julian's extensive diplomatic experience, including spells working with Nato, the UN Security Council and as Chair of the EU's Political and Security Committee, make him perfectly suited to fulfil this role."
King is currently Britain's ambassador to France.