WARSAW — In an unexpectedly tight runoff, Kolinda Grabar-Kitarovic, a conservative challenger, won Croatia’s election on Sunday and is set to become the country’s first female president.

With more than 99 percent of the ballots counted, Ms. Grabar-Kitarovic, 46, won 50.4 percent of the votes, compared with 49.6 percent for President Ivo Josipovic, the center-left incumbent, the electoral commission said.

The election took place in a climate of deep pessimism about Croatia’s economy. The newest member of the European Union, Croatia has one of the weakest economies in the bloc, with an unemployment rate of nearly 20 percent and youth unemployment running at 41.5 percent.

“Let’s go together,” Ms. Grabar-Kitarovic of the opposition Croatian Democratic Union said late Sunday in a speech laced with patriotic wording and interrupted by nationalist soccer chants. “A difficult job awaits us. Let’s unite. Let’s unite our patriotism, love and faith in our Croatian homeland.”