I can’t find any date or documentation releasing these countries from the terms of their surrender or control by American military governors.
In Germany it was a gradual process.
In 1949 the Occupation Statute granted limited self-government to German authorities and replaced military Governors with civilian High Commisioners.
In 1955 the “Germany Treaty” granted a high degree of independence to West Germany but the allies retained certain rights, especially related to West Berlin (which was technically not really part of West Germany) and a possible German reunification.
In 1990 the Two Plus Four Agreement granted full sovereignty to Germany and the allies renounced all their remaining rights.
Well, the Germans surrendered to the Russians first…
As to Japan, the Treaty of San Francisco was signed on September 8, 1951 and officially came into effect on April 28, 1952.
Not quite. German forces in Berlin were forced to surrender to the Soviets, but the German instruments of surrender simultaneously surrendered the nation to the AEF and the Soviet High command.
This treaty only officially ended the war between Japan and the United States and United Kingdom. The Soviet Union, which had declared war on Japan seven days before Japan surrendered, did not sign the treaty because of some unsettled territorial disputes.
The Joint Declaration by Japan and the USSR of October 19, 1956 officially ended the war between the two countries and re-established diplomatic relations. But it was not a peace treaty and did not finalize the territorial issues. While the two countires have continued to issue periodic statements that they are negotiating such an agreement, none has been signed yet.