LOLIN / WEMOS D1 mini V4.0 - ESP8266EX, 4 MB flash, USB-C.
Logic level 3.3 V, the pins are NOT 5 V tolerant, ~12 mA max per pin.
PWM (analogWrite, 0-1023) and interrupts work on every digital pin
except D0 / GPIO16.

Digital header pins

  PIN   GPIO         FUNCTION             AT BOOT               USE
  D0    GPIO16       Deep-sleep wake      HIGH                  limited
  D1    GPIO5        I2C SCL              floating / LOW        free
  D2    GPIO4        I2C SDA              floating / LOW        free
  D3    GPIO0        Boot mode select     HIGH, 10k pull-up     careful
  D4    GPIO2        LED, Serial1 TX      HIGH, 10k pull-up     careful
  D5    GPIO14       HSPI SCK             floating              free
  D6    GPIO12       HSPI MISO            floating              free
  D7    GPIO13       HSPI MOSI            floating              free
  D8    GPIO15       HSPI SS, boot mode   LOW, 10k pull-down    careful

Serial, analog and power pins

  PIN   GPIO         FUNCTION             AT BOOT               USE
  TX    GPIO1        UART0 TX (USB)       HIGH, boot log        occupied
  RX    GPIO3        UART0 RX (USB)       HIGH                  occupied
  A0    ADC0 / TOUT  Analog in, 10 bit    -                     0 - 3.2 V
  RST   EXT_RSTB     Reset, active LOW    -                     pull to GND
  3V3   -            Regulator output     -                     ~500 mA out
  5V    -            USB VBUS / raw in    -                     feed 5 V here
  GND   -            Ground               -                     2x header, 1x JST

JST-SH I2C connector (new on V4.0)

  SIGNAL GPIO     HEADER  MEANING
  SDA    GPIO4    = D2    default Wire data
  SCL    GPIO5    = D1    default Wire clock
  3V3    -        = 3V3   3.3 V supply (not 3.5 V)
  GND    -        = GND   ground

The connector pins sit in parallel with the D1 / D2 header pins -
it is the same two GPIOs, not extra ones.

Not available

GPIO6 - GPIO11 are wired to the SPI flash chip and are not routed to
any header. GPIO9 / GPIO10 are free in DIO flash mode in theory, but
the D1 mini does not break them out.

Boot behaviour - what to watch out for

D3 / GPIO0 must be HIGH at reset; LOW puts the chip into flash mode
D4 / GPIO2 must be HIGH at reset; also LED_BUILTIN, active LOW
D8 / GPIO15 must be LOW at reset; an external pull-up blocks booting
D0 / GPIO16 driven HIGH at boot, no PWM, no interrupt, no I2C
TX / GPIO1 prints the bootloader message at 74880 baud on reset

The board already carries the correct strapping resistors - the risk
comes from what you attach to those pins.

Picking a pin

Best D1, D2 (GPIO5 / GPIO4) - no strapping role, no boot pulse.
Reserve them for I2C only if you actually need I2C.
Next D5, D6, D7 (GPIO14 / GPIO12 / GPIO13) - predictable at
reset, free whenever hardware SPI is unused.
Avoid D3, D4, D8, D0 for relays and MOSFETs - each one is driven
or pulled during boot, so the load twitches on every reset.

For a load that must stay off while the board resets, add a pull-down
resistor at the MOSFET gate and stay on D1, D2, D5, D6 or D7.