Germany has recognised Libya's rebels as "the legitimate representatives of the Libyan people".
"We want a free Libya, in peace and democracy without [Muammar] Gaddafi," Foreign Minister Guido Westerwelle said in the rebel stronghold Benghazi.
About a dozen states have recognised the National Transitional Council.
Germany came under criticism for its refusal to back a UN Security Council resolution authorising Nato action to protect Libyan civilians.
The NTC emerged from the forces which began a revolt against Colonel Gaddafi's rule on 16 February.
After months of bloody conflict, Col Gaddafi remains in control of the capital Tripoli while the rebels hold Benghazi and much of the east.
His government said on Monday it had repulsed an attempt by rebels to take the western town of Zawiya, just 30km (18 miles) from Tripoli.
The town was under rebel control at the start of the revolt but troops backed by tanks recaptured it after two weeks of heavy fighting.
The three-hour visit by Mr Westerwelle and his colleague, Economic Co-operation and Development Minister Dirk Niebel, was the first by German officials to rebel-controlled territory.
Speaking alongside rebel foreign minister Ali Issawi, Mr Westerwelle said: "We share the same goal: Libya without Gaddafi.
"The national council is the legitimate representative of the Libyan people."
Libyans listening burst into applause after he made the announcement.
A senior rebel official, NTC Vice-Chairman Abdel Hafez Ghoga, welcomed the German decision as a "very big step".
German opposition politicians, media commentators and foreign policy experts had sharply criticised the government for its position on Col Gaddafi, accusing it of failing to live up to its international obligations.
It abstained from the UN Security Council resolution backing intervention in Libya and did not directly join Nato's air campaign.
Mr Westerwelle said in Benghazi that staying out of the Nato-led operation did not mean Berlin was being neutral.
"We were one of the first governments to say that Gaddafi must go," he said.
"His assets should be unblocked so they can be used to build a new Libya, whose riches are for the Libyan people."
Mr Niebel said Berlin would work on development projects in Libya, mainly in the sectors of water and electricity.
Germany, he added, wanted to help refugees and "people traumatised by the war".
Battle in the west
Reporters taken to Zawiya by government officials said the green national flag was flying in the central square.
Government spokesman Moussa Ibrahim said an attack by rebel fighters had been driven off.
"The wishful reporting of some journalists that the rebels are gaining more power and more control of some areas is not correct," he said.
"They were defeated after a few hours of scattered skirmishes with the army."
He added that about 100 rebels were under siege just outside the town.
Rebel spokesman M'hamed Ezzawi told Reuters news agency there had been heavy fighting against government forces backed by heavy weapons.
Control of Zawiya would allow the rebels to cut a key supply route to the Tunisian border.