ARLINGTON, Va. — Margaret M. Heckler, an eight-term Republican congresswoman from Massachusetts who later became an embattled secretary of the Department of Health and Human Services under President Ronald Reagan before serving as U.S. ambassador to Ireland, died Aug. 6 at a hospital in Arlington, Va. She was 87.

The cause was cardiac arrest, said her daughter-in-law, Kim Heckler.

Throughout much of her career, Heckler was a groundbreaking figure who often forged her way in law and politics as one of the few women in the male-dominated fields. In 1966, she unseated a former speaker of the House to win the Republican nomination for her district in suburban Boston.

She was the first woman elected to Congress in her own right from Massachusetts and, when she took office in 1967, was one of only 11 women in the U.S. House of Representatives.

During her 16 years in the House, Heckler championed women’s issues, including the Equal Rights Amendment and Title IX, which barred sex discrimination in education. In 1977, she was a co-founder and co-chair of the bipartisan Congressional Caucus for Women’s Issues.

Her signature legislative achievement was the 1974 Equal Credit Opportunity Act, which prohibited banks and lending institutions from denying loans, credit and other financial services based on sex or marital status.

As a Republican from Massachusetts, Ms. Heckler often held positions that could typically be called liberal. Other than a long-held opposition to abortion rights, she had a voting record that was often out of step with her increasingly conservative GOP colleagues.

She often voted against military spending bills and opposed President Richard M. Nixon’s conduct of the war in Vietnam. She also spoke out against Nixon’s veto of day-care legislation, calling it “a serious setback to the concept of child development.”

Throughout the 1970s, Heckler was a leading proponent of the Equal Rights Amendment, an effort to enshrine equal rights for women in the Constitution. When the ratification process slowed in the late 1970s, she was a co-sponsor of resolution to extend the deadline for states to approve the measure. She continued to argue in favor of the ERA at the 1980 Republican National Convention, even as her party grew less receptive to liberal views. (In the end, the ERA was not adopted.)

After redistricting, Heckler lost her congressional seat in 1982 to Democrat Barney Frank. Although she voted against the Reagan administration’s positions more than any other Republican member of Congress, she was promptly nominated to became Reagan’s second secretary of Health and Human Services, after the resignation of Richard S. Schweiker. She was confirmed in March 1983, after saying in her hearings, “I want to be a catalyst for caring in America.”

At HHS, Ms. Heckler managed a department with 145,000 employees and a budget of about $300 billion. She was among the first high-ranking members of the Reagan administration to call for additional federal funding for AIDS research and treatments, calling it the country’s “number one health priority.”

It was as HHS secretary that she addressed at the Class of 1984 at Southeastern Massachusetts University, now UMass Dartmouth.

She also expanded research into the growing problem of Alzheimer’s disease. After White House counselor Edwin Meese publicly doubted whether hunger was a serious problem, Heckler addressed a group of homeless people, saying, “You have as much right to dignity and respect as anyone in this society.” 

Margaret Mary O’Shaughnessy was born June 21, 1931, in the Flushing section of Queens to Irish immigrants. Her father was a hotel doorman, her mother a homemaker.

A talented pianist in her youth, Ms. Heckler became drawn to politics as a student at Albertus Magnus College in New Haven, Conn., when she was elected to a statewide student legislative group.

She was the only woman in her law school class at Boston College, graduating in 1956. While raising her family and practicing law, she served on an advisory council to the governor.

In 1966, Ms. Heckler defeated 42-year incumbent Joseph W. Martin Jr., a former speaker of the House, in the Republican primary.

When she was in Congress, she kept a sign on her desk that read: “Whatever women do, they must do twice as well as men to be thought half as good. Luckily, this is not difficult.”