Credit Gleb Garanich/Reuters
In the past week, however, after President Petro O. Poroshenko called off a cease-fire and ordered his troops to end the rebellion by force, an entirely different Ukrainian military appeared to arrive at the front. Soldiers retook an important checkpoint at the Russian border, routed insurgents from the long-occupied city of Slovyansk, and, on Sunday, began to tighten a noose around the regional capital of Donetsk ahead of a potentially decisive showdown.
The insurgency is far from over, and Ukraine's leaders say they still fear a war with Russia that they would certainly lose. Still, the recent success, however tentative, reflects what officials and analysts described as a remarkable, urgent transformation of the military and security apparatus in recent months.
"The military themselves learned to fight," said Mykola Sungurovskyi, the director of military programs at the Razumkov Center, a policy research organization here in the capital of Ukraine.
By most standards, the Ukrainian armed forces remain in a pitiful state. But they have benefited from the enlistment of thousands of volunteers into new militias, financial donations by ordinary citizens - including a Kiev Internet-technology entrepreneur who raised $35,000 and built a surveillance drone - and an aggressive push to repair and upgrade armored personnel carriers and other equipment.
There has also been aid from abroad. The United States has sent $23 million in security assistance since March, including $5 million for night-vision goggles, body armor, communications equipment and food.
But even more important, experts said, was a reorganization of the chain of command and a crucial psychological shift: Soldiers surmounted a reluctance to open fire on their own countrymen, a serious issue after riot police officers killed about 100 protesters last winter during civil unrest centered on Maidan, the main square in Kiev.
"They have overcome that psychological barrier in which the military were afraid to shoot living people," Mr. Sungurovskyi said. "They had this barrier after Maidan, after the death of that hundred - not simply to shoot living people, but their own people. After the forces were restructured a bit, and it became clear who were our people, who were foes, the operations became more effective."
The biggest test is just ahead.
After fleeing south from Slovyansk, large numbers of rebels appeared Sunday to be regrouping in Donetsk, a city of one million, where any push to contain them will involve dangerous urban warfare. Signaling resilience, insurgents on Sunday seized a building belonging to the state penitentiary service.
In Luhansk, the region's second-largest city after Donetsk, other rebels attacked a jail, allowing eight prisoners to escape. In each case, officials said the rebels, after suffering losses, appeared to be searching for weapons. In recent days, rebel leaders have pleaded with President Vladimir V. Putin of Russia to send additional aid.
Officials and experts agreed that the most urgent task facing the Ukrainian government was sealing its border with Russia to prevent any further influx of fighters or weapons, and the military has made progress doing so. And though he is hardly trusted by Ukrainians, Mr. Putin also sent signals that he would not order a full-scale invasion, announcing, for instance, that Parliament had withdrawn formal authorization for him to use military force in Ukraine.
It is not clear why Mr. Putin eased some of the military pressure, but it appears as if he has decided to put his emphasis on peace talks being coordinated by a close friend of his, Viktor V. Medvedchuk, a Ukrainian businessman and political operative. Although similarly supported by the leaders of Germany and France, the talks have sputtered.
While the fears among officials of a Russian invasion and psychological barriers among Ukrainian troops were quite real, experts said that most of the obstacles confronting the Ukrainian military were far more concrete.
When Russia invaded Crimea in February, for example, Ukraine's military had shrunk to roughly 128,000 troops, including civilians - about one-tenth of its size during Soviet Union times. Of those, only a small fraction were prepared for fighting, said Oleksiy Melnyk, a former Air Force pilot and now a security analyst at the Razumkov Center.
"They were wearing uniforms and going to work every day," Mr. Melnyk said. "The difference with the civilians was just the clothes. They were not trained. They were not equipped." The military's vehicles were decrepit and its weapons outdated, its budget routinely pilfered by corrupt officials.
For instance, from 2005 to 2013, according to public Defense Ministry inventories, the number of helicopters fell to fewer than 75, from more than 300. In February, as Russian forces entered Crimea, there was virtually no way to fight back.
The insurrection that followed in the east then presented an entirely different - and even more confounding - challenge: an insidious type of warfare involving masked rebels who looked and acted like terrorists but had access to weapons and intelligence from Russia, among the world's most advanced military powers.
As Ukrainian leaders considered how hard to push back, they had to confront the danger to civilians of fighting in heavily populated cities, as well as the risk of provoking a full-scale invasion by the conventional Russian forces massing along the border.
It is a fight that experts said had to be carried out largely by special forces, carefully coordinated with the conventional military, including artillery and air force squadrons, which, in the end, have had a limited role.
It is also a fight that Ukraine was not prepared for, but one that Andriy Parubiy, the leader of Ukraine's National Security and Defense Council, said should grab the attention of the world's major powers because of its implications for modern conflict.
"I am convinced that there are many other countries which are not ready - properly speaking, their armed forces are not ready, are unprepared, for this type of war," Mr. Parubiy said in an interview last week. "We, of course, studied the experience of both Croatia and Israel, but here a lot of new features are added. And, if Russia sees that this experience is successful, this experience can very easily be used in any Baltic countries, and even in Belarus and Kazakhstan."
Mr. Parubiy invoked Igor Girkin, a Russian military intelligence officer who has been a commander of the insurrection in eastern Ukraine, under the name of Igor Strelkov. "If we do not stop Putin here," Mr. Parubiy said, "nobody knows where his Girkins will appear next."
In the interview, Mr. Parubiy laid his hands on a table and, exhaling in disgust, described the paralysis of the initial response to the insurgency.
"The key tactic of Russian saboteurs is: Capture a building, station an armed garrison there and have a picket around, mostly Communists, who would provide a human shield," he said, offering an example he witnessed. "They had it this way in Luhansk. There is a five-story building where each window is a firing spot and, right next to the building, are 500 people - a picket.
"When we tell Alpha, a special unit of the S.B.U., whose purpose is to fight terrorists, to enter the building and conduct the operation, they tell us, 'Take away the people because the operation can only be conducted when we are able to enter without a scuffle with civilians,' " he said. "When we tell the interior troops to make a corridor and drag away civilians, they say, 'How can we do that when terrorists in windows point guns at us? We're not able to fulfill this task.' "
The military was so underfinanced that the government issued a plea for donations from citizens. Some of the country's richest businessmen used their personal fortunes to create militias that are now effectively part of a new national guard.
"As one colleague from the United States said, we have to repair a plane during flight," Mr. Parubiy said.
As part of a continuing shake-up of the military, last week Mr. Poroshenko appointed a new defense minister - the country's fourth this year - and a new chief of staff of the armed forces.
Visiting Slovyansk on Sunday, where he praised troops for expelling rebels and where the authorities were delivering food, water and other aid, the new defense minister, Valeriy Heletey, said that the effort to crush the insurgents would continue.
"We will conduct the antiterrorist operation in its active phase until not a single terrorist will remain on the territory of Donetsk and Luhansk regions," he said.
Mr. Melnyk, the security analyst, cautioned that despite recent improvements, the military's work was far from done. "It's still premature to make the assessment that, wow, this is a great success," he said. "There's something going on in Donetsk. Those separatists, terrorists - whatever we want to call them - have decided to make one stronghold."
David Herszenhorn, The New York Times. Daniel Rzhenetskyy contributed reporting.