Russia’s economy shrank sharply in the second quarter as the country felt the brunt of the economic fallout from the war in Ukraine, which experts believe is the start of a year-long recession. The economy shrank by 4 percent from April to June compared with a year earlier, Russia’s statistics agency said on Friday. It is the first quarterly gross domestic product report to fully capture the change in the economy since the invasion of Ukraine in February. It was a sharp reversal from the first quarter, when the economy grew 3.5 percent. Western sanctions, which have cut Russia off about half of its $600 billion emergency foreign exchange and gold reserves, have imposed severe restrictions on transactions with Russian banks and cut off access to American technology, prompting hundreds of major Western companies to withdraw from the country. But even as imports to Russia dried up and financial transactions were blocked, forcing the country to default on its foreign debt, the Russian economy proved more resilient than some economists had initially expected, and the drop in GDP reported on Friday it was not as severe as some expected in part because the country’s coffers were flush with energy revenues as world prices rose. Analysts, however, say the financial toll will rise as Western countries increasingly distance themselves from Russian oil and gas, crucial sources of export revenue. “We thought it would be a deep dive this year and then it would level off,” Laura Solanko, a senior adviser at the Bank of Finland’s Institute for Economies in Transition, said of the Russian economy. Instead, there was a milder economic decline, but it will continue next year, putting the economy in a shallower recession for two years, he said. Russia, a $1.5 trillion economy before the war began, moved quickly in the days after the invasion to soften the impact of the sanctions. The central bank more than doubled interest rates to 20%, severely restricted the flow of money out of the country, closed stock trading on the Moscow Stock Exchange and relaxed bank regulations so that lending would not be seized. The government also increased social spending to support households and loans for businesses hit by the sanctions. The measures soften some of the effects of the sanctions. And as the ruble recovered, Russia’s economy benefited from high oil prices. “Russia has withstood the initial shock of the sanctions” and “has been relatively resilient so far,” said Dmitry Dolgin, chief economist covering Russia at Dutch bank ING. But, he noted, if Russia fails to diversify its trade and finances, the economy will be weaker in the long run. Retail trade fell by about 10 percent, the statistics office said, while wholesale business activity fell by 15 percent. Michael S. Bernstam, a researcher at the Hoover Institution at Stanford University, said the evidence released Friday was consistent with other reports from Russia. It also expects the economy to worsen in the second half of this year and then again in 2023. Filling in St. Petersburg. The outlook for Russia’s energy industry, an important part of the country’s economy, is dim.Credit…Anatoly Maltsev/EPA, via Shutterstock As the war continues, many countries and companies will try to permanently end relations with Russia and its domestic companies. Businesses will have trouble getting spare parts for Western-made machinery, and software will need updates. Russian companies will need to rearrange their supply chains as imports increase. The outlook for Russia’s energy industry, central to the country’s economy, is deteriorating. The United States and Britain have already banned imports of Russian oil, and the country’s oil production will fall further early next year when the full impact of the European Union’s import ban takes effect. Russia will need to find customers for about 2.3 million barrels of crude and oil products per day, about 20% of its average output in 2022, according to the International Energy Agency. So far countries such as India, China and Turkey have absorbed some of the lost trade from Europe and the United States, but it is unclear how many new buyers can be found. Dependence on Russian natural gas is also decreasing. In the last week of June, the European Union’s total natural gas imports from Russia fell by 65% ​​from last year, according to a European Central Bank report. Some of these reductions were imposed in Europe because Russia has reduced its natural gas supplies. However, European countries have stepped up efforts to find alternative sources and, for example, are rapidly developing infrastructure for additional liquefied natural gas imports. The economy will suffer as “the depletion of investment import stocks, the imposition of the EU oil embargo, greater financial pressure on households and greater reliance on the state” take a toll, while the ability of the central bank and government to provide monetary and fiscal support is limited, ING’s Mr. Dolgin wrote. Inflation in Russia was above 15 percent in July.Credit…Yuri Kochetkov/EPA, via Shutterstock Shortly after the invasion of Ukraine, inflation in Russia soared as households sought goods they expected to become scarce. In July, inflation was above 15%, according to the Russian central bank. Already, however, there are signs that inflation is slowing and the central bank has therefore cut interest rates to 8%, lower than before the war. Last month, the bank said business activity had not slowed as much as expected, but that the economic environment “remains challenging and continues to significantly constrain economic activity.” The bank predicted the economy would shrink by 4% to 6% this year, much less than it had initially expected just after the war began. This 6 percent figure also matches the latest update from the International Monetary Fund. The economy will contract deeper next year and not return to growth until 2025, the central bank said on Friday. The bank predicted that inflation would be 12% to 15% by the end of the year. In the coming months, supply chain issues will present challenges as businesses constrained by sanctions try to shift their supply chains to replenish inventories of finished and raw goods. “I don’t think the Russian economy is doing well at the moment,” Ms Solanko said. But the idea that sanctions and the withdrawal of companies from Russia would cause the economy to rapidly collapse was never realistic. “The savings just don’t go away,” he said. The Russian economy will experience a deeper contraction next year and will not return to growth until 2025, the central bank said on Friday.Credit…Maxim Shipenkov/EPA, via Shutterstock — Eshe Nelson and Patricia Cohen Reporting from London.