How do I get the golden key?

On Find Mii/StreetPass Quest, during the Secret Quest, there is a gold key that unlocks a path in the bottom right part of the map. The key is acquired by beating the final enemy in the game, Dark Emperor, with a certain condition, but there are conflicting versions as to what this condition is.
A map in GameFAQs states that you need to finish the final enemy with "25 Miis or less", this thread, however, states that people beat it with 22 Miis and didn't get the key.
So, what is the criteria?
Best Answer
A quote from Dark Toshi from Gamefaqs who has a method of consistently acquiring the golden key
I took the following path (1-2-5-6-10-11-18-26-27-32-33-34-35-36) to ensure that I didn't get the Silver Key by completing rooms 19 & 25.
I killed the Ultimate Ghost each time with a team of two level 7 reds via combo magic. As a result, the fight with the Dark Emperor always began with the two red miis.
I found that the gold key was awarded when I beat the Dark Emperor with 21 miis (this includes the 2 from the Ultimate Ghost battle) in total during the battle itself.
It was NOT awarded when I used 22, 23, 24, and 25 miis against the Dark Emperor with the same condition (beating the Ultimate Ghost with 2 miis). No potions (Vial of Valor, Dispelling Draft) were used in the fight. The number of miis used prior to the Dark Emperor is irrelevant.
Here are the the details of the 21 and 22 mii runs that I did. I am excluding the data for the runs of 23-25 miis since you didn't get the key with 22 miis. I made sure both red miis were cycled through during the fight with the Ultimate Ghost to ensure no mii was miscounted. The 2 miis from the Ultimate Ghost Fight did not increase the counter during the fight with the Dark Emperor.
21 mii run (Gold Key awarded)
Miis used 14 level 7 red 1 level 6 red 6 level 1 red
8 level 7's cast combo magic for 39 damage each time (Dark Emp 94 HP left) 6 level 7's cast single magic for 12 damage each time (Dark Emp 22 HP left) 1 level 6 cast single magic for 10 damage (Dark Emp 12 HP left). 6 level 1's cast single magic for 2 damage each (Dark Emp 0 HP left).
Heroes met counter at start of fight: 31 Heroes met counter at end of fight: 50
22 mii run (no key earned)
Miis used 14 level 7 red 1 level 5 red 7 level 1 red
8 level 7's cast combo magic for 39 damage each time (Dark Emp 94 HP left) 6 level 7's cast single magic for 12 damage each time (Dark Emp 22 HP left) 1 level 5 cast single magic for 8 damage (Dark Emp 14 HP left). 7 level 1's cast single magic for 2 damage each (Dark Emp 0 HP left).
Heroes met counter at start of fight: 39 Heroes met counter at end of fight: 59
The only case I that haven't confirmed is what would have happened if I had beaten the Ultimate Ghost with just one mii instead of two.
Hopefully this will put to rest all the debate on how the gold key is obtained.
Pictures about "How do I get the golden key?"



Quick Answer about "How do I get the golden key?"
How do you get the golden key in sanctuary?
Sanctuary Key The key can be obtained once the Hero has amassed over 5,000,000 gold. You must climb the mountain of gold to obtain it. Also, you automatically obtain the Key (no notification) when you have too much money in your own treasury, approximately when you hit 6,000,000 gold.How do you farm Golden Keys in Borderlands 3?
In order to get Golden Keys, players will need to enter the 25-digit Shift Codes in their possession. This is done by creating an account and entering the code at shift.gearboxsoftware.com, either directly in the browser, or within the game menu in the social tab followed by the Shift Code tab.Terraria - Golden Key, quick guide
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Asiama Junior, EKATERINA BOLOVTSOVA, Non kittitham, Deepak Maurya