Lord Advocate James Wolffe QC and Solicitor General Alison Di Rollo QC have said they will continue in their roles until replacements are appointed.
The lord advocate is the head of Scotland's prosecution body and is the principal legal adviser to the Scottish government. The solicitor general is his deputy.
There have been calls for the lord advocate's role to be split.
In England and Wales, there is an attorney general who gives legal advice to the UK government, as well as a director of public prosecutions.
Scotland's Lord Advocate: Law officer with a dual role
In February, former first minister Alex Salmond said Mr Wolffe should resign over his role in the Scottish government's handling of harassment complaints against him.
Speaking before a Scottish Parliament inquiry into the affair in March, Mr Wolffe denied any political influence relating to Mr Salmond's criminal prosecution, which ultimately saw him acquitted of 13 charges at Edinburgh's High Court last year.
Mr Wolffe told the Holyrood committee: "Any suggestion, from any quarter, that the Crown's decision-making has at any time been influenced by irrelevant considerations or improper motivations would be wholly without foundation.
"Insinuation and assertions to the contrary are baseless."
The controversy led to suggestion from Scottish Labour that the roles should be separated.
And following news of the resignations, Scottish Liberal Democrat justice spokesman Liam McArthur said: "With the departure of the lord advocate this is an opportunity to consider how the role works going forward.
"Scottish Liberal Democrats believe that now is the time to separate the lord advocate's position as the Scottish government's legal advisor and appoint an independent director of prosecutions to run the Crown Office and Procurator Fiscal Service."
Mr Wolffe also made a public apology over the wrongful prosecution of two men following a fraud investigation relating to the sale of Rangers.
He was not the lord advocate at the time of the initial prosecutions of David Whitehouse and Paul Clark.
They had been appointed joint administrators of the club in 2012 but were arrested in 2014 regarding their involvement with the administration.
The pair were later awarded more than £20m after charges brought against them were either dropped or dismissed.
It is not uncommon for Scotland's law officers to change after a Holyrood election but it doesn't happen every time.
The departure of the current lord advocate and solicitor general comes after a period of sustained controversy for the Crown Office.
The Salmond case raised questions about the dual role of law officers - as independent prosecutors and as ministers in, and legal advisers to, the Scottish government.
The SNP manifesto committed to considering whether that dual role should end and to a wider review of the prosecution system.
Both will take place under new leadership to be nominated by Nicola Sturgeon and approved by parliament and the Queen.
Whoever is appointed will have an important role in certifying whether or not any indyref2 bill is within Holyrood's law making powers.
The pair were appointed as Scotland's two law officers in 2016.
Prior to taking on their roles, Mr Wolffe was Dean of the Faculty of Advocates and Ms Di Rollo was head of the National Sexual Crimes Unit.
Their successors will be nominated by First Minister Nicola Sturgeon, then approved by the Scottish Parliament.
The parliament will then recommend the new law officers' appointment to the Queen.
A Scottish government spokesman said the lord advocate informed the first minister last year that he intended to leave office after this month's election, and then confirmed his intention before her re-election by the Scottish Parliament as first minister.
He added that the solicitor general had now confirmed she intended to stand down at the same time.
The spokesman added: "It is for the first minister to nominate new law officers and, subject to approval of her nominees by the Scottish Parliament, to recommend their appointment to Her Majesty the Queen.
"The current law officers intend to remain in office until the new law officers are appointed."