Horthy was forced to appoint right-wing Prime Minister Laszlo Bardossy. Bardossy was a Hitlerphile and convinced (or tricked) Horthy into supporting Operation Barbarossa. The Hungarian Second Army joined the invasion, and was in operation until it was nearly destroyed in the fighting to relieve Stalingrad. The mounting casualties had allowed Horthy to sack Bardossy in March 1942.
Bardossy's successor Miklos Kallay had a dance with the devil - if he openly broke with Hitler, Germany would invade to secure Hungary and her resources. If he did not, the Russians would eventually sack Budapest. He played a dangerous game, appearing loyal to the Nazis while pro-Western Hungarian diplomats to secure guarantees that Allied planes would transit Hungary unmolested.
Kallay was able to bring the remaining Hungarian soldiers home in April 1943, which forced a confrontation with Hitler and the occupation of Hungary. A pro-Nazi government was installed. Thousands of Hungarian Jews were sent to their deaths in the concentration camps. only a third of Hungary's 750,000 Jews survived.
As the Red Army advanced in October 1944, German units destroyed roads and rail lines and cut communications. They abducted Horthy after he tried to negotiate a peace with the Red Army and forced him to abandon his plans. Horty abdicated and intense fighting lasted for seven weeks outside Budapest. Destruction from both the Nazis and the Red Army left Hungary desolate. The last German troops were driven out on April 4, 1945.