WASHINGTON (Reuters) - The U.S. Senate confirmed President Donald Trump’s nominee to be ambassador to Germany on Thursday, just before Chancellor Angela Merkel was due in Washington for talks on Berlin’s desire that Trump preserve the international nuclear agreement with Iran.

The Senate voted 56-42 to confirm Richard Grenell, largely along party lines, filling a position that had been vacant since January 2017. Trump nominated Grenell for the position last September.

Grenell, who has been strongly critical of the nuclear agreement, is a Republican foreign policy writer and commentator who was an aide to Trump’s new national security adviser, John Bolton, when Bolton was former Republican President George W. Bush’s ambassador to the United Nations.

Trump nominated Grenell for the Berlin post last September.

Merkel’s visit comes just after French President Emmanuel Macron was in Washington, calling on the United States not to abandon the nuclear agreement. Separately, Western envoys said on Wednesday that Britain, France and Germany were nearing a package that seeks to persuade Trump to save the pact.

Most Senate Democrats voted against Grenell, citing issues including his history of making statements insulting to women politicians on the Internet and during cable television appearances.

“Will he insult, via his Twitter account, the female chancellor of Germany? I don’t know. I hope not,” Senator Robert Menendez, the top Democrat on the Foreign Relations Committee, said in a Senate speech opposing Grenell.

When asked about such comments during his confirmation hearing, Grenell said he was trying to be funny, not insulting, and would not have made such statements while serving as a U.S. official.

Republican supporters of Grenell dismissed such concerns as political partisanship by Democrats.

Grenell’s confirmation made him the highest-ranking openly gay official in the Trump administration.