Harman was elected as MP for Peckham at a 1982 by-election. She was made a shadow social services minister in 1984 and a shadow health minister in 1987. Under John Smith, she served as Shadow Chief Secretary to the Treasury and, under Tony Blair, as Shadow Employment Secretary, Shadow Health Secretary and Shadow Social Security Secretary respectively. Following the 1997 general election victory, she was appointed Secretary of State for Social Security and the first ever Minister for Women, serving until 1998 when she left the Cabinet. In 2001, she was appointed Solicitor General for England and Wales, serving until 2005 when she became Minister of State for Constitutional Affairs. She ran in the 2007 deputy leadership election and defeated five other candidates, ultimately defeating Secretary of State for Health, Alan Johnson, by 50.43% to 49.56%. Gordon Brown, who was elected as party leader, appointed her Leader of the House of Commons, Lord Privy Seal, Minister for Women and Equality and Chairman of the Labour Party, although she was not appointed Deputy Prime Minister.