A survey revealed that the organisation - one of the most secretive in the world - last year provided staff with quality empl oyment policies, training, career development opportunities, and especially support for LGBT employees.
It beat more than 400 organisations to top workplace equality campaigner Stonewall's Top 100 Employers list for 2016, after coming seventh in 2015.
MI5 executives said that diversity was vital in maintaining the service's high standard workforce.
Director-general Andrew Parker said: "Diversity is vital for MI5, not just because it's right that we represent the communities we serve, but because we rely on the skills of the most talented people whoever they are, and wherever they may be.
"This accolade from Stonewall is a great acknowledgement of the continued progress we have made over recent years in ensuring we draw on the widest possible pool of talent in our vital work."
Other organisations to top the list included Lloyds Banking Group, the National Assembly for Wales, Pinsent Masons and Leicestershire County Council.
Ruth Hunt, Stonewall CEO, said: "Those organisations that are 'getting it right' are not only improving the lives of lesbian, gay, bi and trans staff, stakeholders, clients and customers, but are also reaping business benefits.
"We know that people perform better when they can be themselves, and it's been proven that diversity among staff leads to a more productive, positive and creative workplace environment."