CHICAGO (AP) _ Former Illinois Gov. Richard Ogilvie suffered a massive heart attack at work Monday and was in grave condition following emergency bypass surgery, hospital officials said.

Surgeons performed a quadruple coronary bypass in a five-hour operation that was ''a total success,'' said Dr. Renee Hartz, who led the surgical team.

But she said Ogilvie was in grave condition and his prognosis was ''totally unclear.''

The former governor's heart was beating almost completely on its own after the surgery, Ms. Hartz said, adding doctors would know much more about his chances for recovery in the morning.

His condition was described as ''quite grave, quite guarded'' by Dr. John Sanders, Northwestern's chief of staff, at an afternoon news conference.

''When we operate in the midst of a heart attack in which the heart is unable to provide adequate pumping capability, we can't say with any certainty if the heart will pump adequately when we're done,'' said Sanders, a cardiac surgeon.

The former governor had ''not to anyone's knowledge'' suffered a previous heart attack, Sanders said. But Ogilvie did have ''a history of risk factors,'' the doctor said, adding he did not have the background to elaborate.

Sanders said a triple bypass appeared likely, based on emergency-room instrument readings, which indicated Ogilvie suffered a massive coronary.

The former governor's daughter, Elizabeth, and her husband were at the hospital. Ogilvie's wife, Dorothy, was en route from Florida.

Ogilvie was stricken at his downtown law office. He was ''awake and able to respond'' when he arrived at the hospital, thanks to quick action by paramedics, Sanders said. But surgery was scheduled after his condition deteriorated in the emergency room, Sanders said.

Ogilvie, a Republican, ran for governor in 1968 and served until 1972, when he was defeated by Democrat Dan Walker.

He was born Feb. 22, 1923, the son of a Kansas City, Mo., insurance man whose business took the family first to Evanston and then to Port Chester, N.Y.

Ogilvie graduated from Yale and enrolled in Chicago Kent Law College. He became active in revitalizing the Illinois Young Republicans, and in 1949 joined the law firm of Lord, Bissell & Brook. The next year he married Dorothy Shriver of Oak Park.

In 1958, he left corporate law to head a U.S. Justice Department crime- fighting unit in Chicago. The case that put his name in headlines was his conviction of mob leader Tony Accardo on income-tax evasion charges.

The conviction was subsequently reversed by the 7th U.S. Circuit Court of Appeals, which held that publicity might have biased jurors.

News reports have speculated that Mayor Eugene Sawyer was preparing to make Ogilvie chairman of the Chicago Housing Authority, the troubled public housing agency that provides housing for 145,000 people.