McDonald’s Corp. said revenue ticked down in the second quarter, dragged lower by fewer sales at its company-operated restaurants amid the closure of its locations in Russia and Ukraine.

The fast-food company posted a 3% drop in revenue to $5.72 billion, coming in under analyst projections of $5.8 billion, according to FactSet. Excluding currency effects, including the weaker euro, revenue would have increased 3%, McDonald’s said.

The company said higher prices and value menu offerings pushed same-store sales up 3.7% in the U.S. compared with last year’s period, outpacing analysts’ expectations. But margins at its company-operated stores were hurt by closures from its Russia exit in May, along with inflated labor and commodity costs.

“The operating environment across the competitive landscape remains challenging,” Chief Executive Officer Chris Kempczinski said.

Same-store sales rose 9.7% globally, the company said, noting that it was excluding its Russian stores from that figure.

The company said its profit fell by nearly half to $1.19 billion, or $1.60 a share, during the second quarter, due in part to a pretax charge coming from the sale of its business in Russia.

Excluding that and other one-time items, adjusted earnings were $2.55 a share. Analysts surveyed by FactSet had been expecting $2.47 a share.

McDonald’s is trying to remain attractive to consumers, even as it has been raising prices in response to growing costs for labor, food and materials. The company said in April that its U.S. locations had increased menu prices by an average of 8% in the first quarter, compared with last year’s period.

Some McDonald’s owners have dropped the chain’s U.S. deal offering soda and other cold beverages of any size for a dollar despite the company’s recommendations to keep them. A number of franchisees said they moved away from the longstanding deal in light of rising costs, and dropping it has improved their profit.

Some of the nation’s biggest food suppliers and restaurants, from Kraft Heinz Co. to Campbell Soup Co. , said they would continue to raise prices as they face higher costs. Casual-dining chain BJ’s Restaurants Inc. told investors last week that it would raise its menu prices by 2% next month, after a 1.4% increase in June. Domino’s Pizza Inc. said prices during its most recent quarter rose by nearly 6% on average as it increased costs on menus, offers and delivery fees.

McDonald’s officially exited Russia in May after more than three decades of operations there, selling its hundreds of restaurants to a local franchisee. The company Tuesday reported a $1.3 billion pretax charged for the year connected to the sale of its Russian business.

Russia was a large company-operated market for McDonald’s, which has steadily sold restaurants to franchisees across the world to run. McDonald’s had 847 restaurants in Russia as of last year and owned 84% of them, the company said.

McDonald’s shares were flat premarket. Through Monday’s close, they are up 2.6% this year, compared with a more than 10% drop in the S&P 500.

Write to Heather Haddon at heather.haddon@wsj.com and Dean Seal at dean.seal@wsj.com