diff --git a/docs/news.rst b/docs/news.rst
index 16ed74769..b3281cc2d 100644
--- a/docs/news.rst
+++ b/docs/news.rst
@@ -29,6 +29,10 @@ Psycopg 3.3.9
   made pipeline mode, `~AsyncCursor.executemany()` and `~AsyncCopy.write()`
   on async connections several times slower than on sync ones
   (:ticket:`#1468`).
+- Use the values of ``host``, ``hostaddr``, ``port``, ``connect_timeout``,
+  ``load_balance_hosts``, ``target_session_attrs`` found in the service file,
+  not only the ones in the connection string and in the env vars
+  (:ticket:`#698`).
 - Fix client-side quoting of negative zero floats and decimals, which could
   produce a ``--`` SQL comment (:ticket:`#1480`).
 - Raise `DataError` instead of `!ValueError` registering a composite whose
diff --git a/psycopg/psycopg/_conninfo_utils.py b/psycopg/psycopg/_conninfo_utils.py
index cc5774e23..b9188f353 100644
--- a/psycopg/psycopg/_conninfo_utils.py
+++ b/psycopg/psycopg/_conninfo_utils.py
@@ -7,6 +7,7 @@
 from __future__ import annotations
 
 import os
+import sys
 from functools import lru_cache
 from ipaddress import ip_address
 from dataclasses import dataclass
@@ -68,12 +69,16 @@ def get_param(params: ConnMapping, name: str) -> str | None:
     """
     Return a value from a connection string.
 
-    The value may be also specified in a PG* env var.
+    The value may be also specified in a service file or in a PG* env var.
+    The precedence is the same as in libpq: connection string, service file,
+    env var.
     """
     if name in params:
         return str(params[name])
 
-    # TODO: check if in service
+    if name != "service" and (service := _get_service(params)) is not None:
+        if (val := service.get(name)) is not None:
+            return val
 
     if not (paramdef := get_param_def(name)):
         return None
@@ -84,6 +89,83 @@ def get_param(params: ConnMapping, name: str) -> str | None:
     return None
 
 
+def _get_service(params: ConnMapping) -> dict[str, str] | None:
+    """
+    Return the parameters of the service requested, if any.
+
+    Look for the service in the file specified by ``PGSERVICEFILE``, or in the
+    user and in the system service files, following libpq.
+    """
+    name = get_param(params, "service")
+    if not name:
+        return None
+
+    # Same order as libpq: PGSERVICEFILE or the user file, then the system
+    # file if the service wasn't found there.
+    if fn := os.environ.get("PGSERVICEFILE"):
+        pass
+    elif sys.platform == "win32":
+        appdata = os.environ.get("APPDATA")
+        fn = os.path.join(appdata, "postgresql", ".pg_service.conf") if appdata else ""
+    else:
+        home = os.path.expanduser("~")
+        fn = os.path.join(home, ".pg_service.conf") if home != "~" else ""
+
+    if fn and (rv := _read_service_file(fn, name)) is not None:
+        return rv
+
+    # libpq uses a compile-time SYSCONFDIR if PGSYSCONFDIR is not set. That
+    # value is not known from Python, so in that case the system file is not
+    # read.
+    if sysconf := os.environ.get("PGSYSCONFDIR"):
+        return _read_service_file(os.path.join(sysconf, "pg_service.conf"), name)
+
+    return None
+
+
+def _read_service_file(filename: str, service: str) -> dict[str, str] | None:
+    """
+    Return the parameters of a service in a file, None if not found.
+    """
+    try:
+        mtime = os.stat(filename).st_mtime_ns
+    except OSError:
+        return None
+    return _parse_service_file(filename, mtime).get(service)
+
+
+@lru_cache(maxsize=8)
+def _parse_service_file(filename: str, mtime: int) -> dict[str, dict[str, str]]:
+    # The mtime is only used to invalidate the cache if the file changes.
+    rv: dict[str, dict[str, str]] = {}
+    try:
+        with open(filename, encoding="utf-8", errors="replace") as f:
+            lines = f.read().splitlines()
+    except OSError:
+        return rv
+
+    # Whitespace as in libpq: trim the line, not the key or the value.
+    ws = " \t\n\r\f\v"
+    current: dict[str, str] | None = None
+    for line in lines:
+        line = line.strip(ws)
+        if not line or line.startswith("#"):
+            continue
+        if line.startswith("["):
+            # As in libpq, the first definition of a service wins.
+            name, sep, _ = line[1:].partition("]")
+            if not sep:
+                current = {}  # malformed header: skip its content
+            else:
+                current = {} if name in rv else rv.setdefault(name, {})
+            continue
+        if current is not None and "=" in line:
+            key, val = line.split("=", 1)
+            current.setdefault(key, val)
+
+    return rv
+
+
 @dataclass
 class ParamDef:
     """
diff --git a/tests/test_conninfo.py b/tests/test_conninfo.py
index 62dc22e55..a5b5d739f 100644
--- a/tests/test_conninfo.py
+++ b/tests/test_conninfo.py
@@ -122,3 +122,15 @@ def test_timeout_bad_value(setpgenv, conninfo):
     params = conninfo_to_dict(conninfo)
     with pytest.raises(ProgrammingError, match="bad value for connect_timeout"):
         timeout_from_conninfo(params)
+
+
+def test_timeout_from_service(setpgenv, tmp_path, monkeypatch):
+    setpgenv({"PGCONNECT_TIMEOUT": "7"})
+    fn = tmp_path / "pg_service.conf"
+    fn.write_text("[foo]\nconnect_timeout=11\n")
+    monkeypatch.setenv("PGSERVICEFILE", str(fn))
+    assert timeout_from_conninfo(conninfo_to_dict("service=foo")) == 11
+    # The connection string has precedence on the service
+    assert timeout_from_conninfo(conninfo_to_dict("service=foo connect_timeout=5")) == 5
+    # The service has precedence on the env var
+    assert timeout_from_conninfo(conninfo_to_dict("service=bar")) == 7
diff --git a/tests/test_conninfo_attempts.py b/tests/test_conninfo_attempts.py
index 2c76c287f..fe9890bcb 100644
--- a/tests/test_conninfo_attempts.py
+++ b/tests/test_conninfo_attempts.py
@@ -1,6 +1,8 @@
 # WARNING: this file is auto-generated by 'async_to_sync.py'
 # from the original file 'test_conninfo_attempts_async.py'
 # DO NOT CHANGE! Change the original file instead.
+import sys
+
 import pytest
 
 import psycopg
@@ -196,3 +198,135 @@ def test_conninfo_random_multi_ips(fake_resolve):
     args["load_balance_hosts"] = "random"
     hostaddrs = [str(att["hostaddr"]) for att in conninfo_attempts(args)]
     assert hostaddrs != sorted(hostaddrs)
+
+
+@pytest.fixture
+def service_file(tmp_path, monkeypatch, setpgenv):
+    setpgenv({})
+
+    def write(content):
+        fn = tmp_path / "pg_service.conf"
+        fn.write_text(content)
+        monkeypatch.setenv("PGSERVICEFILE", str(fn))
+
+    return write
+
+
+@pytest.mark.parametrize(
+    "conninfo, want",
+    [
+        (
+            "service=multi",
+            [
+                "service=multi host=1.1.1.1 port=5433 hostaddr=1.1.1.1",
+                "service=multi host=2.2.2.2 port=5433 hostaddr=2.2.2.2",
+            ],
+        ),
+        ("service=multi host=3.3.3.3", ["service=multi host=3.3.3.3 hostaddr=3.3.3.3"]),
+        (
+            "service=names",
+            [
+                "service=names host=foo.com hostaddr=1.1.1.1",
+                "service=names host=qux.com hostaddr=2.2.2.2",
+            ],
+        ),
+    ],
+)
+def test_conninfo_attempts_service(service_file, fake_resolve, conninfo, want):
+    service_file("""# a comment
+[multi]
+host=1.1.1.1,2.2.2.2
+port=5433
+
+[names]
+host=foo.com,qux.com
+""")
+    params = conninfo_to_dict(conninfo)
+    attempts = conninfo_attempts(params)
+    want = list(map(conninfo_to_dict, want))
+    assert want == attempts
+
+
+def test_conninfo_attempts_service_load_balance(
+    service_file, fake_resolve, monkeypatch
+):
+    service_file("[lb]\nhost=dup.com\nload_balance_hosts=random\n")
+    shuffled = []
+    mod = sys.modules[conninfo_attempts.__module__]
+    monkeypatch.setattr(mod, "shuffle", lambda x: shuffled.append(list(x)))
+    params = conninfo_to_dict("service=lb")
+    conninfo_attempts(params)
+    assert shuffled
+
+
+@pytest.fixture
+def service_env(tmp_path, monkeypatch, setpgenv):
+    setpgenv({})
+    for name in ("PGSERVICEFILE", "PGSYSCONFDIR", "APPDATA", "PGSERVICE"):
+        monkeypatch.delenv(name, raising=False)
+    return tmp_path
+
+
+def test_conninfo_attempts_pgservice_env(service_env, monkeypatch, fake_resolve):
+    fn = service_env / "svc.conf"
+    fn.write_text("[envsvc]\nhost=1.1.1.1,2.2.2.2\n")
+    monkeypatch.setenv("PGSERVICEFILE", str(fn))
+    monkeypatch.setenv("PGSERVICE", "envsvc")
+    attempts = conninfo_attempts(conninfo_to_dict(""))
+    assert [a["hostaddr"] for a in attempts] == ["1.1.1.1", "2.2.2.2"]
+
+
+def test_conninfo_attempts_service_system_fallback(
+    service_env, monkeypatch, fake_resolve
+):
+    # Service not in PGSERVICEFILE: libpq tries $PGSYSCONFDIR/pg_service.conf
+    user = service_env / "user.conf"
+    user.write_text("[other]\nhost=9.9.9.9\n")
+    sysdir = service_env / "sys"
+    sysdir.mkdir()
+    (sysdir / "pg_service.conf").write_text("[sysonly]\nhost=3.3.3.3,4.4.4.4\n")
+    monkeypatch.setenv("PGSERVICEFILE", str(user))
+    monkeypatch.setenv("PGSYSCONFDIR", str(sysdir))
+    attempts = conninfo_attempts(conninfo_to_dict("service=sysonly"))
+    assert [a["hostaddr"] for a in attempts] == ["3.3.3.3", "4.4.4.4"]
+
+    # A service found in the first file wins over the system file
+    (sysdir / "pg_service.conf").write_text("[other]\nhost=8.8.8.8,7.7.7.7\n")
+    attempts = conninfo_attempts(conninfo_to_dict("service=other"))
+    assert [a["hostaddr"] for a in attempts] == ["9.9.9.9"]
+
+
+def test_conninfo_attempts_service_whitespace(service_env, monkeypatch, fake_resolve):
+    # As in libpq: lines are trimmed, key and value are not.
+    fn = service_env / "svc.conf"
+    lines = ["  [ws]  ", "  host=1.1.1.1,2.2.2.2  ", "[bad", "host=5.5.5.5"]
+    fn.write_text("\n".join(lines))
+    monkeypatch.setenv("PGSERVICEFILE", str(fn))
+    attempts = conninfo_attempts(conninfo_to_dict("service=ws"))
+    assert [a["hostaddr"] for a in attempts] == ["1.1.1.1", "2.2.2.2"]
+
+
+def test_conninfo_attempts_service_windows_appdata(
+    service_env, monkeypatch, fake_resolve
+):
+    # On Windows libpq reads %APPDATA%\postgresql\.pg_service.conf
+    appdata = service_env / "appdata"
+    (appdata / "postgresql").mkdir(parents=True)
+    (appdata / "postgresql" / ".pg_service.conf").write_text(
+        "[win]\nhost=1.1.1.1,2.2.2.2\n"
+    )
+    monkeypatch.setenv("APPDATA", str(appdata))
+    mod = sys.modules["psycopg._conninfo_utils"]
+    monkeypatch.setattr(mod, "sys", type("S", (), {"platform": "win32"}))
+    attempts = conninfo_attempts(conninfo_to_dict("service=win"))
+    assert [a["hostaddr"] for a in attempts] == ["1.1.1.1", "2.2.2.2"]
+
+
+def test_conninfo_attempts_service_posix_home(service_env, monkeypatch, fake_resolve):
+    # On POSIX libpq reads ~/.pg_service.conf
+    (service_env / ".pg_service.conf").write_text("[home]\nhost=1.1.1.1,2.2.2.2\n")
+    mod = sys.modules["psycopg._conninfo_utils"]
+    monkeypatch.setattr(mod, "sys", type("S", (), {"platform": "linux"}))
+    monkeypatch.setattr(mod.os.path, "expanduser", lambda p: str(service_env))
+    attempts = conninfo_attempts(conninfo_to_dict("service=home"))
+    assert [a["hostaddr"] for a in attempts] == ["1.1.1.1", "2.2.2.2"]
diff --git a/tests/test_conninfo_attempts_async.py b/tests/test_conninfo_attempts_async.py
index 8b694ddc8..921566a5e 100644
--- a/tests/test_conninfo_attempts_async.py
+++ b/tests/test_conninfo_attempts_async.py
@@ -1,3 +1,5 @@
+import sys
+
 import pytest
 
 import psycopg
@@ -203,3 +205,143 @@ async def test_conninfo_random_multi_ips(fake_resolve):
     args["load_balance_hosts"] = "random"
     hostaddrs = [str(att["hostaddr"]) for att in await conninfo_attempts_async(args)]
     assert hostaddrs != sorted(hostaddrs)
+
+
+@pytest.fixture
+def service_file(tmp_path, monkeypatch, setpgenv):
+    setpgenv({})
+
+    def write(content):
+        fn = tmp_path / "pg_service.conf"
+        fn.write_text(content)
+        monkeypatch.setenv("PGSERVICEFILE", str(fn))
+
+    return write
+
+
+@pytest.mark.parametrize(
+    "conninfo, want",
+    [
+        (
+            "service=multi",
+            [
+                "service=multi host=1.1.1.1 port=5433 hostaddr=1.1.1.1",
+                "service=multi host=2.2.2.2 port=5433 hostaddr=2.2.2.2",
+            ],
+        ),
+        (
+            "service=multi host=3.3.3.3",
+            ["service=multi host=3.3.3.3 hostaddr=3.3.3.3"],
+        ),
+        (
+            "service=names",
+            [
+                "service=names host=foo.com hostaddr=1.1.1.1",
+                "service=names host=qux.com hostaddr=2.2.2.2",
+            ],
+        ),
+    ],
+)
+async def test_conninfo_attempts_service(service_file, fake_resolve, conninfo, want):
+    service_file(
+        "# a comment\n"
+        "[multi]\n"
+        "host=1.1.1.1,2.2.2.2\n"
+        "port=5433\n"
+        "\n"
+        "[names]\n"
+        "host=foo.com,qux.com\n"
+    )
+    params = conninfo_to_dict(conninfo)
+    attempts = await conninfo_attempts_async(params)
+    want = list(map(conninfo_to_dict, want))
+    assert want == attempts
+
+
+async def test_conninfo_attempts_service_load_balance(
+    service_file, fake_resolve, monkeypatch
+):
+    service_file("[lb]\nhost=dup.com\nload_balance_hosts=random\n")
+    shuffled = []
+    mod = sys.modules[conninfo_attempts_async.__module__]
+    monkeypatch.setattr(mod, "shuffle", lambda x: shuffled.append(list(x)))
+    params = conninfo_to_dict("service=lb")
+    await conninfo_attempts_async(params)
+    assert shuffled
+
+
+@pytest.fixture
+def service_env(tmp_path, monkeypatch, setpgenv):
+    setpgenv({})
+    for name in ("PGSERVICEFILE", "PGSYSCONFDIR", "APPDATA", "PGSERVICE"):
+        monkeypatch.delenv(name, raising=False)
+    return tmp_path
+
+
+async def test_conninfo_attempts_pgservice_env(service_env, monkeypatch, fake_resolve):
+    fn = service_env / "svc.conf"
+    fn.write_text("[envsvc]\nhost=1.1.1.1,2.2.2.2\n")
+    monkeypatch.setenv("PGSERVICEFILE", str(fn))
+    monkeypatch.setenv("PGSERVICE", "envsvc")
+    attempts = await conninfo_attempts_async(conninfo_to_dict(""))
+    assert [a["hostaddr"] for a in attempts] == ["1.1.1.1", "2.2.2.2"]
+
+
+async def test_conninfo_attempts_service_system_fallback(
+    service_env, monkeypatch, fake_resolve
+):
+    # Service not in PGSERVICEFILE: libpq tries $PGSYSCONFDIR/pg_service.conf
+    user = service_env / "user.conf"
+    user.write_text("[other]\nhost=9.9.9.9\n")
+    sysdir = service_env / "sys"
+    sysdir.mkdir()
+    (sysdir / "pg_service.conf").write_text("[sysonly]\nhost=3.3.3.3,4.4.4.4\n")
+    monkeypatch.setenv("PGSERVICEFILE", str(user))
+    monkeypatch.setenv("PGSYSCONFDIR", str(sysdir))
+    attempts = await conninfo_attempts_async(conninfo_to_dict("service=sysonly"))
+    assert [a["hostaddr"] for a in attempts] == ["3.3.3.3", "4.4.4.4"]
+
+    # A service found in the first file wins over the system file
+    (sysdir / "pg_service.conf").write_text("[other]\nhost=8.8.8.8,7.7.7.7\n")
+    attempts = await conninfo_attempts_async(conninfo_to_dict("service=other"))
+    assert [a["hostaddr"] for a in attempts] == ["9.9.9.9"]
+
+
+async def test_conninfo_attempts_service_whitespace(
+    service_env, monkeypatch, fake_resolve
+):
+    # As in libpq: lines are trimmed, key and value are not.
+    fn = service_env / "svc.conf"
+    lines = ["  [ws]  ", "  host=1.1.1.1,2.2.2.2  ", "[bad", "host=5.5.5.5"]
+    fn.write_text("\n".join(lines))
+    monkeypatch.setenv("PGSERVICEFILE", str(fn))
+    attempts = await conninfo_attempts_async(conninfo_to_dict("service=ws"))
+    assert [a["hostaddr"] for a in attempts] == ["1.1.1.1", "2.2.2.2"]
+
+
+async def test_conninfo_attempts_service_windows_appdata(
+    service_env, monkeypatch, fake_resolve
+):
+    # On Windows libpq reads %APPDATA%\postgresql\.pg_service.conf
+    appdata = service_env / "appdata"
+    (appdata / "postgresql").mkdir(parents=True)
+    (appdata / "postgresql" / ".pg_service.conf").write_text(
+        "[win]\nhost=1.1.1.1,2.2.2.2\n"
+    )
+    monkeypatch.setenv("APPDATA", str(appdata))
+    mod = sys.modules["psycopg._conninfo_utils"]
+    monkeypatch.setattr(mod, "sys", type("S", (), {"platform": "win32"}))
+    attempts = await conninfo_attempts_async(conninfo_to_dict("service=win"))
+    assert [a["hostaddr"] for a in attempts] == ["1.1.1.1", "2.2.2.2"]
+
+
+async def test_conninfo_attempts_service_posix_home(
+    service_env, monkeypatch, fake_resolve
+):
+    # On POSIX libpq reads ~/.pg_service.conf
+    (service_env / ".pg_service.conf").write_text("[home]\nhost=1.1.1.1,2.2.2.2\n")
+    mod = sys.modules["psycopg._conninfo_utils"]
+    monkeypatch.setattr(mod, "sys", type("S", (), {"platform": "linux"}))
+    monkeypatch.setattr(mod.os.path, "expanduser", lambda p: str(service_env))
+    attempts = await conninfo_attempts_async(conninfo_to_dict("service=home"))
+    assert [a["hostaddr"] for a in attempts] == ["1.1.1.1", "2.2.2.2"]
