ISTANBUL — A slim majority of Turkish voters agreed on Sunday to grant sweeping powers to their president, in a watershed moment that the country’s opposition fears may cement a system of authoritarian rule within one of the critical power brokers of the Middle East.

With nearly 99 percent of votes in a referendum counted on Sunday night, supporters of the proposal had 51.3 percent of votes cast, and opponents had 48.7 percent, the country’s electoral commission announced.

The result will take days to confirm, and the main opposition party said it would demand a recount of about 37 percent of ballot boxes, containing around 2.5 million votes.

But on Sunday night the result was already a political reality, as President Recep Tayyip Erdogan hailed his victory in front of a crowd of supporters in Istanbul. “We are enacting the most important governmental reform of our history,” he said.