This answer refers to the U.S. government only; although many other countries have a government seat with this same title.
The U.S. Secretary of State is the highest ranking Cabinet official and is appointed by the President of the United States. Although the Executive Branch of the government is appointed and serves at the pleasure of the President, its members must be confirmed by the U.S. Senate; one of the two elected branches of congress. The S.O.S. is fourth in line for the presidency should anything happen to the President, the Vice President of the Speaker of the House of Representatives (the other elected branch of the U.S.Congress).
The Secretary of State oversees and advises the President on U.S. foreign policy; serving the role equivalent of Foreign Ministry. In addition, the S.O.S. oversees all diplomatic relations with other countries; with the exception of some military endeavors. The S.O.S is responsible for protocol functions for the White House. Protocol can best be described as a set of international courtesy rules.
The Secretary of State is also keeper of the Great Seal of the United States, a device used to authenticate documents coming from the White House and as such, the S.O.S. is responsible for drafting proclamations and replies.
In the West Wing, the Secretary of State was Arnold Vinick played by Alan Alda.